I need to extract an icon resource from a file. I have a structure (Resource
) that contains the byte array, size, find handle, load handle, lock handle (from FindResource
, LoadResource
and LockResource
, respectively).
I know that I need to obtain the Icon handle of my icon. Then I need to use GetIconInfo to retrieve the bit-mask. Then I use Image.FromHbitmap(h)
to get an image. I then use the dimensions of the image as parameters to CreateIconFromResourceEx
to retrieve a properly sized Icon.
Does anyone have some code to do this? I can declare all P/Invoke myself. Thanks!
My original code is returning a 32x32 every time.
Dim out As ICONINFO
Dim h As IntPtr = res.hLock
GetIconInfo(h, out)
Dim s As Image = Image.FromHbitmap(out.hbmMask)
h = ResourceExplorer.CreateIconFromResourceEx(res.bArray, res.hSize, True, &H30000, s.Width, s.Height, 0)
PictureBox1.Image = Icon.FromHandle(h).ToBitmap