Icon.ToBitmap Method
Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
The following code example demonstrates how to use the ToBitmap method. This example is designed to be used with Windows Forms. Create a form and paste the following code into it. Call the IconToBitmap method in the form's .Paint event handler, passing e as PaintEventArgs .
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Icon.ToBitmap does preserve transparency. However, I've had some 'Overflows' with 256x256 icons.
'Bitmap.FromHIcon doesn't do that, but loses colors and sharpness.
P.S.: Try this 'dirty bit:
Dim ic as New Drawing.Icon("path-to-icon")
Dim bm As Drawing.Bitmap= Bitmap.FromStream(New MemoryStream( _
CType(ic.GetType.GetField("iconData", CType(60, BindingFlags)).GetValue(ic), Byte())))
- 3/25/2012
- jma2400