Hello
The icons with the alpha channel are supported in WindowsXP. If use the
System.Drawing. Bitmap.ToBitmap on the icon handle(ico.ToBi tmap), the alpha
channel won't be preserved, resulting in an ugly black border where the
alpha area. But if the icons with the alpha channel must be show in a
picuturebox, how to do?
Picturebox1.Ima ge=???
The article http://www.vbaccelerator.com/home/NE...jects/Getting_
File_Icons_Usin g_The_Shell/article.asp
Thanks 5 1910
Your best bet is to use DrawIcon on the Picturebox's Graphics Object.
If you really want an Alpha Image:
First of all you need to extract the hBitmap from the Icon and use that to
create your bitmap.
When you create a new bitmap, from existing data, it has an RGB format. The
Alpha channel is not recognised even though the BitmapData does contain it.
To overcome this you must create a second blank bitmap with the ARGB format
and copy the bits to it.
The following code shows how to do this: (note: this will produce a blank
bitmap if the image does not have an Alpha channel)
*************** *************** ***********
Imports System.Drawing. Imaging
Imports System.Runtime. InteropServices
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
...
Code Ommitted
...
#End Region
#Region " Win32 API "
Private Structure ICONINFO
Dim fIcon As Boolean
Dim xHotspot As Integer
Dim yHotspot As Integer
Dim hbmMask As IntPtr 'hBitmap
Dim hbmColor As IntPtr 'hBitmap
End Structure
<DllImport("use r32", _
CallingConventi on:=CallingConv ention.Cdecl)> _
Private Shared Function GetIconInfo( _
ByVal hIcon As IntPtr, _
ByRef piconinfo As ICONINFO) _
As Boolean
End Function
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) _
Handles MyBase.Load
Dim ico As New Icon("MyPath\My Icon.ico")
Dim ii As New ICONINFO
GetIconInfo(ico .Handle, ii)
Dim bmp As Bitmap = Bitmap.FromHbit map(ii.hbmColor )
PictureBox1.Ima ge = New Bitmap(FixAlpha Bitmap(bmp))
End Sub
Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _
As Bitmap
'WARNING! This function will fail if the passed bitmap is
'not of the correct Pixelformat.
Dim bmData(1) As Imaging.BitmapD ata
Dim bmBounds As New Rectangle(0, 0, _
bmSource.Width, _
bmSource.Height )
Dim bmArray((bmSour ce.Width * bmSource.Height ) - 1) _
As Integer
bmData(0) = bmSource.LockBi ts(bmBounds, _
ImageLockMode.R eadOnly, _
bmSource.PixelF ormat)
Dim dstBitmap As New Bitmap(bmData(0 ).Width, _
bmData(0).Heigh t, _
bmData(0).Strid e, _
PixelFormat.For mat32bppArgb, _
bmData(0).Scan0 )
bmData(1) = dstBitmap.LockB its(bmBounds, _
ImageLockMode.W riteOnly, _
dstBitmap.Pixel Format)
Marshal.Structu reToPtr(bmData( 0).Scan0, _
bmData(1).Scan0 , _
True)
bmSource.Unlock Bits(bmData(0))
dstBitmap.Unloc kBits(bmData(1) )
Return dstBitmap
End Function
End Class
*************** *************** ***********
HTH
Mick
"yxq" <ga***@163.ne t> wrote in message
news:eo******** ******@TK2MSFTN GP11.phx.gbl... Hello The icons with the alpha channel are supported in WindowsXP. If use the System.Drawing. Bitmap.ToBitmap on the icon handle(ico.ToBi tmap), the alpha channel won't be preserved, resulting in an ugly black border where the alpha area. But if the icons with the alpha channel must be show in a picuturebox, how to do? Picturebox1.Ima ge=???
The article http://www.vbaccelerator.com/home/NE...jects/Getting_ File_Icons_Usin g_The_Shell/article.asp
Thanks
Hello
Thank you, it works well!
But if i use API PickIconDlg and ExtractIcon to get icon from *.dll files,
how to know whether the icons have Alpha channel? It does not work when the
icons have no Alpha channel. if the icons have no Alpha channel, i can use
"ico.Tobitm ap".
Thanks
"Mick Doherty" <md*******@nosp am.ntlworld.com > дÈëÏûÏ¢ÐÂÎÅ
:O9************ **@TK2MSFTNGP10 .phx.gbl... Your best bet is to use DrawIcon on the Picturebox's Graphics Object.
If you really want an Alpha Image: First of all you need to extract the hBitmap from the Icon and use that to create your bitmap. When you create a new bitmap, from existing data, it has an RGB format.
The Alpha channel is not recognised even though the BitmapData does contain
it. To overcome this you must create a second blank bitmap with the ARGB
format and copy the bits to it. The following code shows how to do this: (note: this will produce a blank bitmap if the image does not have an Alpha channel)
*************** *************** *********** Imports System.Drawing. Imaging Imports System.Runtime. InteropServices
Public Class Form1 Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code " ... Code Ommitted ... #End Region
#Region " Win32 API "
Private Structure ICONINFO Dim fIcon As Boolean Dim xHotspot As Integer Dim yHotspot As Integer Dim hbmMask As IntPtr 'hBitmap Dim hbmColor As IntPtr 'hBitmap End Structure
<DllImport("use r32", _ CallingConventi on:=CallingConv ention.Cdecl)> _ Private Shared Function GetIconInfo( _ ByVal hIcon As IntPtr, _ ByRef piconinfo As ICONINFO) _ As Boolean End Function
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) _ Handles MyBase.Load
Dim ico As New Icon("MyPath\My Icon.ico") Dim ii As New ICONINFO GetIconInfo(ico .Handle, ii) Dim bmp As Bitmap = Bitmap.FromHbit map(ii.hbmColor ) PictureBox1.Ima ge = New Bitmap(FixAlpha Bitmap(bmp))
End Sub
Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _ As Bitmap
'WARNING! This function will fail if the passed bitmap is 'not of the correct Pixelformat. Dim bmData(1) As Imaging.BitmapD ata Dim bmBounds As New Rectangle(0, 0, _ bmSource.Width, _ bmSource.Height )
Dim bmArray((bmSour ce.Width * bmSource.Height ) - 1) _ As Integer
bmData(0) = bmSource.LockBi ts(bmBounds, _ ImageLockMode.R eadOnly, _ bmSource.PixelF ormat)
Dim dstBitmap As New Bitmap(bmData(0 ).Width, _ bmData(0).Heigh t, _ bmData(0).Strid e, _ PixelFormat.For mat32bppArgb, _ bmData(0).Scan0 )
bmData(1) = dstBitmap.LockB its(bmBounds, _ ImageLockMode.W riteOnly, _ dstBitmap.Pixel Format)
Marshal.Structu reToPtr(bmData( 0).Scan0, _ bmData(1).Scan0 , _ True)
bmSource.Unlock Bits(bmData(0)) dstBitmap.Unloc kBits(bmData(1) )
Return dstBitmap
End Function
End Class
*************** *************** ***********
HTH
Mick
"yxq" <ga***@163.ne t> wrote in message news:eo******** ******@TK2MSFTN GP11.phx.gbl... Hello The icons with the alpha channel are supported in WindowsXP. If use
the System.Drawing. Bitmap.ToBitmap on the icon handle(ico.ToBi tmap), the
alpha channel won't be preserved, resulting in an ugly black border where the alpha area. But if the icons with the alpha channel must be show in a picuturebox, how to do? Picturebox1.Ima ge=???
The article http://www.vbaccelerator.com/home/NE...jects/Getting_ File_Icons_Usin g_The_Shell/article.asp
Thanks
I haven't worked that one out yet.
I think, but have not confirmed, that the Bitmap returned, when there is no
Alpha channel, is not actually blank, it's just fully Transparent.
I am no expert in Bitmap structures so it took me a while to come up with
that solution. However, I would expect that you need to get the Bitmap
Header and check for it there.
I suppose you could loop through the BitmapData bits and check the Alpha bit
for each Color. If all Alpha Bits are zero then there is no Alpha Channel,
so return the original bitmap. I'll look into that and let you know if I can
get it to work.
"yxq" <ga***@163.ne t> wrote in message
news:eM******** ******@TK2MSFTN GP11.phx.gbl... Hello Thank you, it works well! But if i use API PickIconDlg and ExtractIcon to get icon from *.dll files, how to know whether the icons have Alpha channel? It does not work when
the icons have no Alpha channel. if the icons have no Alpha channel, i can use "ico.Tobitm ap".
Thanks
"Mick Doherty" <md*******@nosp am.ntlworld.com > дÈëÏûÏ¢ÐÂÎÅ :O9************ **@TK2MSFTNGP10 .phx.gbl... Your best bet is to use DrawIcon on the Picturebox's Graphics Object.
If you really want an Alpha Image: First of all you need to extract the hBitmap from the Icon and use that
to create your bitmap. When you create a new bitmap, from existing data, it has an RGB format. The Alpha channel is not recognised even though the BitmapData does contain it. To overcome this you must create a second blank bitmap with the ARGB format and copy the bits to it. The following code shows how to do this: (note: this will produce a
blank bitmap if the image does not have an Alpha channel)
*************** *************** *********** Imports System.Drawing. Imaging Imports System.Runtime. InteropServices
Public Class Form1 Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code " ... Code Ommitted ... #End Region
#Region " Win32 API "
Private Structure ICONINFO Dim fIcon As Boolean Dim xHotspot As Integer Dim yHotspot As Integer Dim hbmMask As IntPtr 'hBitmap Dim hbmColor As IntPtr 'hBitmap End Structure
<DllImport("use r32", _ CallingConventi on:=CallingConv ention.Cdecl)> _ Private Shared Function GetIconInfo( _ ByVal hIcon As IntPtr, _ ByRef piconinfo As ICONINFO) _ As Boolean End Function
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) _ Handles MyBase.Load
Dim ico As New Icon("MyPath\My Icon.ico") Dim ii As New ICONINFO GetIconInfo(ico .Handle, ii) Dim bmp As Bitmap = Bitmap.FromHbit map(ii.hbmColor ) PictureBox1.Ima ge = New Bitmap(FixAlpha Bitmap(bmp))
End Sub
Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _ As Bitmap
'WARNING! This function will fail if the passed bitmap is 'not of the correct Pixelformat. Dim bmData(1) As Imaging.BitmapD ata Dim bmBounds As New Rectangle(0, 0, _ bmSource.Width, _ bmSource.Height )
Dim bmArray((bmSour ce.Width * bmSource.Height ) - 1) _ As Integer
bmData(0) = bmSource.LockBi ts(bmBounds, _ ImageLockMode.R eadOnly, _ bmSource.PixelF ormat)
Dim dstBitmap As New Bitmap(bmData(0 ).Width, _ bmData(0).Heigh t, _ bmData(0).Strid e, _ PixelFormat.For mat32bppArgb, _ bmData(0).Scan0 )
bmData(1) = dstBitmap.LockB its(bmBounds, _ ImageLockMode.W riteOnly, _ dstBitmap.Pixel Format)
Marshal.Structu reToPtr(bmData( 0).Scan0, _ bmData(1).Scan0 , _ True)
bmSource.Unlock Bits(bmData(0)) dstBitmap.Unloc kBits(bmData(1) )
Return dstBitmap
End Function
End Class
*************** *************** ***********
HTH
Mick
"yxq" <ga***@163.ne t> wrote in message news:eo******** ******@TK2MSFTN GP11.phx.gbl... Hello The icons with the alpha channel are supported in WindowsXP. If use the System.Drawing. Bitmap.ToBitmap on the icon handle(ico.ToBi tmap), the alpha channel won't be preserved, resulting in an ugly black border where
the alpha area. But if the icons with the alpha channel must be show in a picuturebox, how to do? Picturebox1.Ima ge=???
The article
http://www.vbaccelerator.com/home/NE...jects/Getting_ File_Icons_Usin g_The_Shell/article.asp
Thanks
Well it seems that the returned blank bitmap is indeed blank not just
transparent.
Looping through the Bitmap bits does not offer any help.
The only solution I can think of is to get the information from the Icon
File itself. I found some details on Icon File structure at this address:
<http://www.iconolog.ne t/info/icoFormat.html>
Now all that remains is to set up a BinaryFileReade r to extract the relevant
data. That VBAccelerator example you looked at does that, but I am having
trouble following it to get the Info I want, so I will write my own routine
based on the information from the iconolog.net link above. I'm fitting this
in with other stuff so if you find a solution before me I would appreciate
the feedback.
p.s. Whilst playing around I discovered that you do not need that
Marshal.Structu reToPtr() call or to lock/unlock the dstBitmap. When we
created dstBitmap we set its bits to the address of bmSource's bits with the
Scan0 IntPtr, so both bitmaps occupy the same memory. FixAlphaBitmap now
becomes:
Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _
As Bitmap
'WARNING! This function will fail if the passed bitmap is
'not of the correct Pixelformat.
Dim bmData As Imaging.BitmapD ata
Dim bmBounds As New Rectangle(0, 0, _
bmSource.Width, _
bmSource.Height )
bmData = bmSource.LockBi ts(bmBounds, _
ImageLockMode.R eadOnly, _
bmSource.PixelF ormat)
Dim dstBitmap As New Bitmap(bmData.W idth, _
bmData.Height, _
bmData.Stride, _
PixelFormat.For mat32bppArgb, _
bmData.Scan0)
bmSource.Unlock Bits(bmData)
Return dstBitmap
End Function
Mick
"Mick Doherty" <md*******@nosp am.ntlworld.com > wrote in message
news:eG******** ******@tk2msftn gp13.phx.gbl... I haven't worked that one out yet. I think, but have not confirmed, that the Bitmap returned, when there is
no Alpha channel, is not actually blank, it's just fully Transparent. I am no expert in Bitmap structures so it took me a while to come up with that solution. However, I would expect that you need to get the Bitmap Header and check for it there. I suppose you could loop through the BitmapData bits and check the Alpha
bit for each Color. If all Alpha Bits are zero then there is no Alpha Channel, so return the original bitmap. I'll look into that and let you know if I
can get it to work.
"yxq" <ga***@163.ne t> wrote in message news:eM******** ******@TK2MSFTN GP11.phx.gbl... Hello Thank you, it works well! But if i use API PickIconDlg and ExtractIcon to get icon from *.dll
files, how to know whether the icons have Alpha channel? It does not work when the icons have no Alpha channel. if the icons have no Alpha channel, i can
use "ico.Tobitm ap".
Thanks
"Mick Doherty" <md*******@nosp am.ntlworld.com > дÈëÏûÏ¢ÐÂÎÅ :O9************ **@TK2MSFTNGP10 .phx.gbl... Your best bet is to use DrawIcon on the Picturebox's Graphics Object.
If you really want an Alpha Image: First of all you need to extract the hBitmap from the Icon and use
that to create your bitmap. When you create a new bitmap, from existing data, it has an RGB
format. The Alpha channel is not recognised even though the BitmapData does
contain it. To overcome this you must create a second blank bitmap with the ARGB format and copy the bits to it. The following code shows how to do this: (note: this will produce a blank bitmap if the image does not have an Alpha channel)
*************** *************** *********** Imports System.Drawing. Imaging Imports System.Runtime. InteropServices
Public Class Form1 Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code " ... Code Ommitted ... #End Region
#Region " Win32 API "
Private Structure ICONINFO Dim fIcon As Boolean Dim xHotspot As Integer Dim yHotspot As Integer Dim hbmMask As IntPtr 'hBitmap Dim hbmColor As IntPtr 'hBitmap End Structure
<DllImport("use r32", _ CallingConventi on:=CallingConv ention.Cdecl)> _ Private Shared Function GetIconInfo( _ ByVal hIcon As IntPtr, _ ByRef piconinfo As ICONINFO) _ As Boolean End Function
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) _ Handles MyBase.Load
Dim ico As New Icon("MyPath\My Icon.ico") Dim ii As New ICONINFO GetIconInfo(ico .Handle, ii) Dim bmp As Bitmap = Bitmap.FromHbit map(ii.hbmColor ) PictureBox1.Ima ge = New Bitmap(FixAlpha Bitmap(bmp))
End Sub
Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _ As Bitmap
'WARNING! This function will fail if the passed bitmap is 'not of the correct Pixelformat. Dim bmData(1) As Imaging.BitmapD ata Dim bmBounds As New Rectangle(0, 0, _ bmSource.Width, _ bmSource.Height )
Dim bmArray((bmSour ce.Width * bmSource.Height ) - 1) _ As Integer
bmData(0) = bmSource.LockBi ts(bmBounds, _ ImageLockMode.R eadOnly, _ bmSource.PixelF ormat)
Dim dstBitmap As New Bitmap(bmData(0 ).Width, _ bmData(0).Heigh t, _ bmData(0).Strid e, _ PixelFormat.For mat32bppArgb, _ bmData(0).Scan0 )
bmData(1) = dstBitmap.LockB its(bmBounds, _ ImageLockMode.W riteOnly, _ dstBitmap.Pixel Format)
Marshal.Structu reToPtr(bmData( 0).Scan0, _ bmData(1).Scan0 , _ True)
bmSource.Unlock Bits(bmData(0)) dstBitmap.Unloc kBits(bmData(1) )
Return dstBitmap
End Function
End Class
*************** *************** ***********
HTH
Mick
"yxq" <ga***@163.ne t> wrote in message news:eo******** ******@TK2MSFTN GP11.phx.gbl... > Hello > The icons with the alpha channel are supported in WindowsXP. If
use the > System.Drawing. Bitmap.ToBitmap on the icon handle(ico.ToBi tmap), the alpha > channel won't be preserved, resulting in an ugly black border where the > alpha area. But if the icons with the alpha channel must be show in
a > picuturebox, how to do? > Picturebox1.Ima ge=??? > > The article >
http://www.vbaccelerator.com/home/NE...jects/Getting_ > File_Icons_Usin g_The_Shell/article.asp > > > Thanks > >
Well that turned out to be pretty simple.
If GetIconBitsPerP ixel returns less than 32 then use Icon.ToBitmap
**** Code Starts *************** *************** ******
#Region " IconStructureIn fo "
'Icon File Structure Info courtesy of:
'http://www.iconolog.ne t/info/icoFormat.html
Private Structure ICONFILE
Dim Reserved As Short
Dim ResourceType As Short
Dim IconCount As Short
Dim IconDir() As ICONENTRY
Dim IconData() As IconData
End Structure
Private Structure ICONENTRY
Dim Width As Byte
Dim Height As Byte
Dim NumColors As Byte
Dim Reserved As Byte
Dim NumPlanes As Short
Dim BitsPerPixel As Short
Dim DataSize As Integer
Dim DataOffset As Integer
End Structure
Private Structure ICONDATA
Dim header As BITMAPINFOHEADE R
Dim Palette() As PALETTEENTRY
Dim XorMap() As Byte
Dim AndMap() As Byte
End Structure
Private Structure BITMAPINFOHEADE R '40 bytes
Dim biSize As Integer
Dim biWidth As Integer
Dim biHeight As Integer
Dim biPlanes As Short
Dim biBitCount As Short
Dim biCompression As Integer
Dim biSizeImage As Integer
Dim biXPelsPerMeter As Integer
Dim biYPelsPerMeter As Integer
Dim biClrUsed As Integer
Dim biClrImportant As Integer
End Structure
Private Structure PALETTEENTRY
Dim peRed As Byte
Dim peGreen As Byte
Dim peBlue As Byte
Dim peFlags As Byte
End Structure
#End Region
Private Function GetIconBitsPerP ixel(ByVal iconfile As String) _
As Integer
Dim fs As New IO.FileStream(i confile, IO.FileMode.Ope n)
Dim BR As New IO.BinaryReader (fs)
Dim iFile As New ICONFILE
iFile.Reserved = BR.ReadInt16
iFile.ResourceT ype = BR.ReadInt16
iFile.IconCount = BR.ReadInt16
ReDim iFile.IconDir(i File.IconCount)
Dim id(iFile.IconCo unt) As ICONENTRY
Dim MaxColors As Integer = 0
For i As Integer = 1 To iFile.IconCount
id(i).Width = BR.ReadByte
id(i).Height = BR.ReadByte
id(i).NumColors = BR.ReadByte
id(i).Reserved = BR.ReadByte
id(i).NumPlanes = BR.ReadInt16
id(i).BitsPerPi xel = BR.ReadInt16
id(i).DataSize = BR.ReadInt32
id(i).DataOffse t = BR.ReadInt32
If id(i).BitsPerPi xel > MaxColors Then
MaxColors = id(i).BitsPerPi xel
End If
Next
fs.Close()
BR.Close()
If iFile.ResourceT ype = 1 Then
Return MaxColors
End If
End Function
**** Code Ends *************** *************** *******
Mick
"Mick Doherty" <md*******@nosp am.ntlworld.com > wrote in message
news:OG******** ******@TK2MSFTN GP10.phx.gbl... Well it seems that the returned blank bitmap is indeed blank not just transparent. Looping through the Bitmap bits does not offer any help. The only solution I can think of is to get the information from the Icon File itself. I found some details on Icon File structure at this address: <http://www.iconolog.ne t/info/icoFormat.html> Now all that remains is to set up a BinaryFileReade r to extract the
relevant data. That VBAccelerator example you looked at does that, but I am having trouble following it to get the Info I want, so I will write my own
routine based on the information from the iconolog.net link above. I'm fitting
this in with other stuff so if you find a solution before me I would appreciate the feedback.
p.s. Whilst playing around I discovered that you do not need that Marshal.Structu reToPtr() call or to lock/unlock the dstBitmap. When we created dstBitmap we set its bits to the address of bmSource's bits with
the Scan0 IntPtr, so both bitmaps occupy the same memory. FixAlphaBitmap now becomes:
Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _ As Bitmap
'WARNING! This function will fail if the passed bitmap is 'not of the correct Pixelformat. Dim bmData As Imaging.BitmapD ata Dim bmBounds As New Rectangle(0, 0, _ bmSource.Width, _ bmSource.Height )
bmData = bmSource.LockBi ts(bmBounds, _ ImageLockMode.R eadOnly, _ bmSource.PixelF ormat)
Dim dstBitmap As New Bitmap(bmData.W idth, _ bmData.Height, _ bmData.Stride, _ PixelFormat.For mat32bppArgb, _ bmData.Scan0)
bmSource.Unlock Bits(bmData)
Return dstBitmap
End Function
Mick
"Mick Doherty" <md*******@nosp am.ntlworld.com > wrote in message news:eG******** ******@tk2msftn gp13.phx.gbl... I haven't worked that one out yet. I think, but have not confirmed, that the Bitmap returned, when there is no Alpha channel, is not actually blank, it's just fully Transparent. I am no expert in Bitmap structures so it took me a while to come up
with that solution. However, I would expect that you need to get the Bitmap Header and check for it there. I suppose you could loop through the BitmapData bits and check the Alpha bit for each Color. If all Alpha Bits are zero then there is no Alpha
Channel, so return the original bitmap. I'll look into that and let you know if I can get it to work.
"yxq" <ga***@163.ne t> wrote in message news:eM******** ******@TK2MSFTN GP11.phx.gbl... Hello Thank you, it works well! But if i use API PickIconDlg and ExtractIcon to get icon from *.dll files, how to know whether the icons have Alpha channel? It does not work
when the icons have no Alpha channel. if the icons have no Alpha channel, i can use "ico.Tobitm ap".
Thanks
"Mick Doherty" <md*******@nosp am.ntlworld.com > дÈëÏûÏ¢ÐÂÎÅ :O9************ **@TK2MSFTNGP10 .phx.gbl... > Your best bet is to use DrawIcon on the Picturebox's Graphics
Object. > > If you really want an Alpha Image: > First of all you need to extract the hBitmap from the Icon and use that to > create your bitmap. > When you create a new bitmap, from existing data, it has an RGB format. The > Alpha channel is not recognised even though the BitmapData does contain it. > To overcome this you must create a second blank bitmap with the ARGB format > and copy the bits to it. > The following code shows how to do this: (note: this will produce a blank > bitmap if the image does not have an Alpha channel) > > *************** *************** *********** > Imports System.Drawing. Imaging > Imports System.Runtime. InteropServices > > Public Class Form1 > Inherits System.Windows. Forms.Form > > #Region " Windows Form Designer generated code " > ... > Code Ommitted > ... > #End Region > > #Region " Win32 API " > > Private Structure ICONINFO > Dim fIcon As Boolean > Dim xHotspot As Integer > Dim yHotspot As Integer > Dim hbmMask As IntPtr 'hBitmap > Dim hbmColor As IntPtr 'hBitmap > End Structure > > <DllImport("use r32", _ > CallingConventi on:=CallingConv ention.Cdecl)> _ > Private Shared Function GetIconInfo( _ > ByVal hIcon As IntPtr, _ > ByRef piconinfo As ICONINFO) _ > As Boolean > End Function > > #End Region > > Private Sub Form1_Load(ByVa l sender As System.Object, > ByVal e As System.EventArg s) _ > Handles MyBase.Load > > Dim ico As New Icon("MyPath\My Icon.ico") > Dim ii As New ICONINFO > GetIconInfo(ico .Handle, ii) > Dim bmp As Bitmap = Bitmap.FromHbit map(ii.hbmColor ) > PictureBox1.Ima ge = New Bitmap(FixAlpha Bitmap(bmp)) > > End Sub > > Private Function FixAlphaBitmap( ByRef bmSource As Bitmap) _ > As Bitmap > > 'WARNING! This function will fail if the passed bitmap is > 'not of the correct Pixelformat. > Dim bmData(1) As Imaging.BitmapD ata > Dim bmBounds As New Rectangle(0, 0, _ > bmSource.Width, _ > bmSource.Height ) > > Dim bmArray((bmSour ce.Width * bmSource.Height ) - 1) _ > As Integer > > bmData(0) = bmSource.LockBi ts(bmBounds, _ > ImageLockMode.R eadOnly, _ > bmSource.PixelF ormat) > > Dim dstBitmap As New Bitmap(bmData(0 ).Width, _ > bmData(0).Heigh t, _ > bmData(0).Strid e, _ > PixelFormat.For mat32bppArgb, _ > bmData(0).Scan0 ) > > bmData(1) = dstBitmap.LockB its(bmBounds, _ > ImageLockMode.W riteOnly, _ > dstBitmap.Pixel Format) > > Marshal.Structu reToPtr(bmData( 0).Scan0, _ > bmData(1).Scan0 , _ > True) > > bmSource.Unlock Bits(bmData(0)) > dstBitmap.Unloc kBits(bmData(1) ) > > Return dstBitmap > > End Function > > End Class > > *************** *************** *********** > > HTH > > Mick > > "yxq" <ga***@163.ne t> wrote in message > news:eo******** ******@TK2MSFTN GP11.phx.gbl... > > Hello > > The icons with the alpha channel are supported in WindowsXP. If use the > > System.Drawing. Bitmap.ToBitmap on the icon handle(ico.ToBi tmap),
the alpha > > channel won't be preserved, resulting in an ugly black border
where the > > alpha area. But if the icons with the alpha channel must be show
in a > > picuturebox, how to do? > > Picturebox1.Ima ge=??? > > > > The article > > >
http://www.vbaccelerator.com/home/NE...jects/Getting_ > > File_Icons_Usin g_The_Shell/article.asp > > > > > > Thanks > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yxq |
last post by:
Hello
There are resource code to get file icons, i have test it, it can get file
icon but not get folder icons!
How to get a folder icons?
Thanks
'===========================================================================
==========
' clsIcon
|
by: yxq |
last post by:
Hello
I found a icon Class, i have tested the code, it can get file and drive
icons, but not folder icons,
How to get a folder icon?
Thanks
*************************************************************************
'===========================================================================
==========
' clsIcon
|
by: Tony Lugg |
last post by:
I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them...
|
by: Tony Lugg |
last post by:
I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |