In an ArcMap 10 add-in, I am attempting to create a toggle button of sorts whose image changes based on the button's state.

This answer describes how to set an add-in button's image programmatically and I am using the same technique. The problem is that this method does not appear to support full alpha channel transparency, only single-color transparency, so those fancy PNG icons they added at ArcGIS 10 don't look quite right.

The button's image is set initially by the add-in framework (using a 32-bit PNG file with alpha channel) -- the image looks as you would expect with proper partial transparency.

To create the image toggling behavior, in the button's OnClick method, I check the state of a boolean variable and set the button's image (using the technique in the above-mentioned answer) to one of two bitmaps stored as resources in the add-in assembly. This all works fine except that the button's image is given a gray background instead of a transparent background.

I have searched around a bit and come to the conclusion that ESRI's GetIPictureDispFromBitmap method converts from a GDI+ bitmap to a GDI bitmap and in doing so loses the alpha channel of the original bitmap.

I have found a solution to this issue and will post it as an answer shortly.

1 Answer 1


To maintain partial alpha channel transparency, an IPictureDisp object must be created using some unmanaged code, described in this post on Ryan Gregg's blog.

Copy the C# (mirror) or VB.NET (mirror) code to a new code file and add it to your project. Then, instead of the technique in the previously-mentioned answer, set ICommandItem.FaceID to the return value of PictureDispConverter.ToIPictureDisp, passing in your original bitmap.

For example:

UID uid = new UIDClass();
uid.Value = ThisAddIn.IDs.MyButton;
ICommandItem cmdItem = ArcMap.Application.Document.CommandBars.Find(uid, true, true);
cmdItem.FaceID = PictureDispConverter.ToIPictureDisp(Resources.MyButtonEnabledState);

The partially-transparent areas of the original bitmap should be maintained.

  • In pasting this code into my project, there is no reference to the variable 'stdole'. Do you know what this is supposed to be?
    – cndnflyr
    Aug 14, 2015 at 16:45
  • stdole.dll is a Microsoft Office Primary Interoperability Assembly (PIA): msdn.microsoft.com/en-us/library/aa195478%28office.11%29.aspx
    – blah238
    Aug 14, 2015 at 20:45
  • Thanks! Found it. Didn't expect a referenced dll to be called 'stdole'.
    – cndnflyr
    Aug 17, 2015 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.