Discussion:
Converting transparent bitmaps to IPictureDisp
(too old to reply)
Chris Morrison
2003-12-10 16:25:02 UTC
Permalink
Hi all,

I am writing an Add-In for Visual Studio.NET using C#.

My Add-In adds items to the Edit menu and creates it's own toolbar. Each
command has it's own bitmap icon.

I have given each bitmap a magenta background and I am creating the images
in my code using:

System.Drawing.Bitmap MyToolbarPic = new
System.Drawing.Bitmap("C:\\Pictures\\picture.bmp");
MyToolbarPic.MakeTransparent(Color.FromArgb(255, 0, 255));

I am then adding the icon to my toolbar button using

MyCommandBarButton.Picture = ImageConverter.ImageToIPicture(MyToolbarPic);
// The Picture property requires an IPictureDisp object.

The definition of the ImageConverter Class is:

public class ImageConverter : System.Windows.Forms.AxHost
{
public ImageConverter() : base("59EE46BA-677D-4d20-BF10-8D8067CB8B33")
{
}

public static stdole.IPictureDisp ImageToIPicture(System.Drawing.Image
image)
{
return
(stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image);
}

public static System.Drawing.Image IPictureToImage(stdole.IPictureDisp
picture)
{
return ImageConverter.GetPictureFromIPicture(picture);
}
}

However, instead of being drawn with a transparent background, the icons are
drawn with a blue background.

Any ideas anyone?


Chris
Max
2003-12-21 07:39:56 UTC
Permalink
I had same problem trying to set up menu item bitmap using SetMenuItemInfo
Win32 API function and HBITMAP obtained from transparent Bitmap or Icon.

I did not find any solution, except replacing transparent colour with menu
background colour.

Good luck.

"Chris Morrison"
Post by Chris Morrison
Hi all,
I am writing an Add-In for Visual Studio.NET using C#.
My Add-In adds items to the Edit menu and creates it's own toolbar. Each
command has it's own bitmap icon.
I have given each bitmap a magenta background and I am creating the images
System.Drawing.Bitmap MyToolbarPic = new
System.Drawing.Bitmap("C:\\Pictures\\picture.bmp");
MyToolbarPic.MakeTransparent(Color.FromArgb(255, 0, 255));
I am then adding the icon to my toolbar button using
MyCommandBarButton.Picture = ImageConverter.ImageToIPicture(MyToolbarPic);
// The Picture property requires an IPictureDisp object.
public class ImageConverter : System.Windows.Forms.AxHost
{
public ImageConverter() : base("59EE46BA-677D-4d20-BF10-8D8067CB8B33")
{
}
public static stdole.IPictureDisp ImageToIPicture(System.Drawing.Image
image)
{
return
(stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image);
}
public static System.Drawing.Image IPictureToImage(stdole.IPictureDisp
picture)
{
return ImageConverter.GetPictureFromIPicture(picture);
}
}
However, instead of being drawn with a transparent background, the icons are
drawn with a blue background.
Any ideas anyone?
Chris
Rob
2006-07-17 20:16:32 UTC
Permalink
I had the same problem...

If you also set the mask property of your button, you'll be able to get a transparent icon. The mask should be your icon with the image colored black and the transparent part colored black.

button.Picture = ImageConverter.ImageToIPicture(MyToolbarPic);
button.Mask = ImageConverter.ImageToIPicture(MyToolbarMask);

Hope this helps,

Ro

From http://developmentnow.com/g/21_2003_12_0_0_104727/Converting-transparent-bitmaps-to-IPictureDisp.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com

Loading...