W
WALDO
I have an interesting quandary.
I have developed a program in VB.Net to extract an icon resource from an
exe/dll or from an ico file and enumerate its formats (16x16,256
color;32x32,true color;etc.). It reads out the structures all the way down
to the ICONIMAGE structures. I have this represented as an array of bytes
read from the resource. I am using the unmanaged function
CreateIconFromResourceEx to generate an hIcon pointer. I take this icon
pointer and pass it into the FromHandle method of a System.Drawing.Icon.
Everything works beautifully with one exception. When the icon format is
monochrome, the height from the System.Drawing.Icon is doubled. I understand
that the biHeight from the BITMAPINFOHEADER structure is doubled to account
for both the XOR (color) and AND (transparent) masks, but I am passing the
correct desired height (biHeight / 2) into CreateIconFromResourceEx.
Is there something wrong with the pointer I'm getting back, or is there
something wrong with System.Drawing.Icon that it doesn't understand
monochrome icons?
[VB.Net Pseudocode]
Public Structure ICONIMAGE
Public pBits() As Byte 'All the bytes that make up the structure from
the resource.
Public Function GetHeader As BITMAPINFOHEADER
....
End Function
End Structure
....
Dim img as ICONIMAGE
....
Dim bmi As BITMAPINFOHEADER = img.GetHeader()
Dim width As Integer = bmi.biWidth
Dim height As Integer = bmi.biHeight \ 2
Dim flags As Integer = 0
If IsMonoChrome() Then
flags = flags Or LR_MONOCHROME
End If
Dim hIcon As IntPtr
hIcon = CreateIconFromResourceEx(img.lpBits, ico.idEntries(i).dwBytesInRes,
True, &H30000, width, height, flags)
Dim icon As System.Drawing.Icon
icon = icon.FromHandle(hIcon)
Debug.WriteLine(i, "i")
Debug.WriteLine(icon.Size, "Size")
Debug.WriteLine("")
....
I have developed a program in VB.Net to extract an icon resource from an
exe/dll or from an ico file and enumerate its formats (16x16,256
color;32x32,true color;etc.). It reads out the structures all the way down
to the ICONIMAGE structures. I have this represented as an array of bytes
read from the resource. I am using the unmanaged function
CreateIconFromResourceEx to generate an hIcon pointer. I take this icon
pointer and pass it into the FromHandle method of a System.Drawing.Icon.
Everything works beautifully with one exception. When the icon format is
monochrome, the height from the System.Drawing.Icon is doubled. I understand
that the biHeight from the BITMAPINFOHEADER structure is doubled to account
for both the XOR (color) and AND (transparent) masks, but I am passing the
correct desired height (biHeight / 2) into CreateIconFromResourceEx.
Is there something wrong with the pointer I'm getting back, or is there
something wrong with System.Drawing.Icon that it doesn't understand
monochrome icons?
[VB.Net Pseudocode]
Public Structure ICONIMAGE
Public pBits() As Byte 'All the bytes that make up the structure from
the resource.
Public Function GetHeader As BITMAPINFOHEADER
....
End Function
End Structure
....
Dim img as ICONIMAGE
....
Dim bmi As BITMAPINFOHEADER = img.GetHeader()
Dim width As Integer = bmi.biWidth
Dim height As Integer = bmi.biHeight \ 2
Dim flags As Integer = 0
If IsMonoChrome() Then
flags = flags Or LR_MONOCHROME
End If
Dim hIcon As IntPtr
hIcon = CreateIconFromResourceEx(img.lpBits, ico.idEntries(i).dwBytesInRes,
True, &H30000, width, height, flags)
Dim icon As System.Drawing.Icon
icon = icon.FromHandle(hIcon)
Debug.WriteLine(i, "i")
Debug.WriteLine(icon.Size, "Size")
Debug.WriteLine("")
....