Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create Image object from icon in unmanaged resource-dll

Status
Not open for further replies.

MKuiper

Programmer
Jan 29, 2002
364
NL
Hello all,

I need to display icons on Windows Forms. The icons are kept in an unmanaged resource-only dll.
This is what I have done so far:

1. using InterOp, call LoadLibrary and LoadIcon API's
2. Bitmap bitmap = Bitmap.FromHIcon ( <returned handle from LoadIcon> )
3. bitmap.MakeTransparent ( <All kinds of parameters tried here> )
4. Image image = Image.FromHBitmap(bitmap.GetHBitmap())
5. using InterOp, call DestroyIcon and FreeLibrary API's

Problem with this code is, transparency is lost. What should be transparent is displayed blue (I think it is RGB 0, 0, 211).

Who knows how to get the transparency back?

Thanks in advance,

Marcel
 
Problem solved by replacing step 2, 3 and 4 with:

Icon icon = System.Drawing.Icon.FromHandle(hIcon);
MemoryStream ms = new MemoryStream();
icon.Save(ms);
image = System.Drawing.Image.FromStream(ms);

Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top