Alpha chanelling on bitmap

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
Hello.

I am using the following code (which works fine) to extract icon images from the Windows shell.

VB.NET:
   Public Declare Auto Function ExtractIcon Lib "shell32" (ByVal hInstance As IntPtr,ByVal lpszExeFileName As String,ByVal nIconIndex As Integer) As IntPtr

    Public Function geticon(ByVal id As Integer) As Image
        Dim hIcon As IntPtr = ExtractIcon(Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)), "C:\windows\system32\shell32.dll", id)
        Return Bitmap.FromHicon(hIcon)
    End Function

However the Alpha chanel areas (soft shadow) show up a horrible black because of this line:
VB.NET:
Bitmap.FromHicon(hIcon)
Which converts the handle to a bitmap, which seems to not support Alpha chanels. Is there a way to do the same principle but keep the Alpha chanelling? For example can I cut out the bitmap part and wrap the handle straight to an image or something?

Thanks for great support here :)

- James
 
VB.NET:
Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As IntPtr) As Int32

Public Function geticon(ByVal id As Integer) As Image
    Dim hIcon As IntPtr = ExtractIcon(Me.Handle, "C:\windows\system32\shell32.dll", id)
    Dim i As Icon = Icon.FromHandle(hIcon)
    Dim img As Image = i.ToBitmap
    DestroyIcon(i.Handle)
    Return img
End Function
 
Back
Top