By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,479 Members | 988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,479 IT Pros & Developers. It's quick & easy.

How to get the icon with alpha channel using ExtractIconEx api?

P: n/a
yxq
Hello,
I use the API ExtractIcon to get icon from Shell32, but the returned icon
lost alpha channel, how get back the alpha channel? thank you.

************************************************** ********************************************
Private Declare Function ExtractIconEx Lib "shell32.dll" Alias
"ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Int32, ByRef
phiconLarge As Int32, ByRef phiconSmall As Int32, ByVal nIcons As Int32) As
Int32
Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As
Int32) As Int32

Function getIconFromFilename(ByVal filename As String, ByVal iconIndex
As Int16, ByVal largeIcon As Boolean) As Bitmap

Dim iconLarge As Int32
Dim iconSmall As Int32
If (ExtractIconEx(filename, iconIndex, iconLarge, iconSmall, 1) > 0)
Then
Dim iconPtr As IntPtr

If largeIcon = True Then
iconPtr = New IntPtr(iconLarge)
Else
iconPtr = New IntPtr(iconSmall)
End If

Dim iconRes As Icon = Icon.FromHandle(iconPtr)

Dim returnBitmap As Bitmap = iconRes.ToBitmap
iconRes.Dispose()
If iconLarge <> 0 Then DestroyIcon(iconLarge)
If iconSmall <> 0 Then DestroyIcon(iconSmall)
Return returnBitmap
Else
Return Nothing
End If

End Function
Apr 6 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.