Click here to Skip to main content
15,888,098 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Im trying to save an icon (that was extracted from .exe resource) on a Windows CE 5.0 device. CF.NET System.Drawing.Icon has no Save method.

GetIconInfo gives a ICONINFO structure. If I could get the DIB bits from the Color and Mask bitmaps in ICONINFO, then I could use this to make a ICONIMAGE. But, coredll has no GetDIBits function.
Posted

1 solution

Well I answered my own question. I took me like a week to figure this out and I really appreciate how easy .NET is now.

To get the byte array you have to use CreateDIBSection and then BitBlt (you might be able to just use Graphics.FromHdc to DrawImage instead of BitBlt). I tried to use Lockbits method, but the bitmap height is negative from GetIconInfo and the image comes out upside-down. ( I tried to correct this by reversing the array when the height was negative, but that didnt work.)

Anyway thats for the color bitmap. For the black and white mask- you have to convert it to 1bit per pixel monochrome bitmap. This is not so easy in CF either - there is no 1bpp pixelFormat, so you cant just create a new bitmap and unlock the bits there. I used CreateDIBSection, drew the bitmap onto that, using a new BITMAPINFOHEADER that is 1bpp and using 1 for the colors argument in CreateDIBSection.

Is this the best way? Why cant I just use Marshal.PtrToStructure or Marshal.Copy on the hIcon. (I tried these but i dont know what they are - Marshal.SizeOf(icon.Handle) is something too short to be meaningful, like 13.)

I would put the code, but it has so many parts- I make it a dll. How can I attach a zip file here?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900