Thanks to the second for the question and for the first for the url.
It will be of great help the next time i need that conversion.
good work ===================
* Marta Oliveira *
===================
marta100@aeiou.pt
-------------------
CPC_TA- Braga
-------------------
Portugal
===================
And here's my attempt at much the same thing (obviously there's some cheating going on...). As ever from me, this is an illustrative example, and is missing niceties such as error checking:
' Returns a 32 * 32 windows icon from any of the following picture sources: .ICO .CUR .JPG .BMP .GIF
' Optionally specify the size of the returned icon
Public Function GetIconFromImage(strImage As String, Optional width As Long = 32, Optional height As Long = 32) As Picture
Dim il As Object
' Leverage the ImageList control
Set il = CreateObject("MSComCtlLib.imagelistctrl"
il.ImageWidth = width
il.ImageHeight = height
il.ListImages.Add , , LoadPicture(strImage)
Set GetIconFromImage = il.ListImages(1).ExtractIcon ' The magic bit. Make the control do all the work for you
' Clean up
Set il = Nothing
End Function
Firstly, PaintPicture knows how to paint 'icons' correctly, with transparency (for years programmers have used a set of API calls involving creating memory and device compatible DCs along with various bitblits with appropriate ROPS applied to achieve this). So, by selecting the ListImages mask color and setting the UseMaskColor setting, we can easily paint pictures with transparent areas with zero additional effort.
Secondly, for those programmers who still want handles to the masked and unmasked bitmap handles for a given source, they can be very quickly determined by using something similar to the following:
Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long
Private Type ICONINFO
fIcon As Long
xHotspot As Long
yHotspot As Long
hbmMask As Long
hbmColor As Long
End Type
' Assumes ListImage is still loaded with our image as shown in previous example
public function GethMask() as long
Dim iconic As ICONINFO
Form1.PaintPicture ImageList1.ListImages(1).ExtractIcon, 0, 0
GetIconInfo ImageList1.ListImages(1).ExtractIcon, iconic
GethMask=iconic.hbmIcon
' iconic.hbmColor contains handle to unmasked bitmap
end function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.