loIcon = _SCREEN.SYSTEM.drawing.ICON.fromhandle(hIcon) * create an image the size of the icon (by default, with transparency capabilities) loImg = _Screen.System.Drawing.Bitmap.New(m.loIcon.Size.Width, m.loIcon.Size.Height) * prepare a graphic rendering surface, based on the image loGraphic = _Screen.System.Drawing.Graphics.FromImage(m.loImg) * prepare a rectangle where to draw the icon loRectangle = _Screen.System.Drawing.Rectangle.New(0, 0, m.loImg.Size.Width, m.loImg.Size.Height) * and draw the icon loGraphic.DrawIcon(m.loIcon, m.loRectangle)Now, loImg can be saved or processed as a PNG or other transparency capable format.
>LPARAMETERS ext, tnSize > >#DEFINE SHGFI_ICON 0x000000100 >#DEFINE SHGFI_SMALLICON 0x000000001 >#DEFINE SHGFI_TYPENAME 0x000000400 >#DEFINE SHGFI_USEFILEATTRIBUTES 0x000000010 >#DEFINE FILE_ATTRIBUTE_NORMAL 0x00000080 > >DECLARE INTEGER SHGetFileInfo IN shell32; > STRING pszPath,; > LONG dwFileAttributes,; > STRING @psfi,; > LONG cbFileInfo,; > LONG uFlags >DECLARE SHORT DestroyIcon IN user32 INTEGER hIcon > >LOCAL cext, nBufsize, cBuffer, nFlags,; > nResult, hIcon > >LOCAL lcExt, nBufSize, cBuffer, nFlags, nResult, hIcon > >cext = "."+ext >nBufsize=1024 >cBuffer = REPLICATE(CHR(0), nBufsize) >nFlags = BITOR(SHGFI_ICON, SHGFI_SMALLICON, ; > SHGFI_TYPENAME, SHGFI_USEFILEATTRIBUTES) >nResult = SHGetFileInfo(cext, FILE_ATTRIBUTE_NORMAL, ; > @cBuffer, nBufsize, nFlags) >hIcon = THIS.buf2dword(SUBSTR(cBuffer, 1, 4)) >>
>LOCAL loicon AS xfcicon >loIcon = _SCREEN.SYSTEM.drawing.ICON.fromhandle(hIcon) > >LOCAL loTempfile AS Tempfile OF utils_filehandler.vcx >loTempfile = NewObject("Tempfile","utils_filehandler.vcx") >loTempfile.Create(, "ICO") > >loIcon.SAVE(loTempfile.Path, .T.) && high quality icons by setting the tlquality flag to .t. >RELEASE loIcon > >loBitmap = _SCREEN.System.Drawing.Bitmap.FromFile(loTempFile.Path) >loBitmap.Save("c:\flies\test.bmp", _SCREEN.SYSTEM.drawing.Imaging.ImageFormat.png) >>