Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Issue with icon file
Message
From
06/04/2020 10:59:30
 
 
To
06/04/2020 06:27:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01673979
Message ID:
01673990
Views:
61
This message has been marked as a message which has helped to the initial question of the thread.
Christian,

My reply upfront to let all of your message intact and mine more to the point.

I don't have a fool proof solution, first of all because I'm not observing a constant behavior when these icons are produced. Sometimes they come with the black background, other times they don't.

That said: according to Microsoft's documentation, when an Icon is converted into a Bitmap, the transparency is lost, and its info transformed into a color. The docs say RGB(13, 11, 12), but apparently that is not so: my experience (and yours, I believe) is that the transparency is marked as black (RGB(0, 0, 0)).

So, my solution (so far) is to rebuild the transparency of the image on the bitmap, with a call to the MakeTransparent() method. In your case, that would be something close to
loBlack = _Screen.System.Drawing.Color.New(RGB(0, 0, 0))
loBitmap = _SCREEN.System.Drawing.Bitmap.FromFile(loTempFile.Path)
loBitmap.MakeTransparent(m.loBlack)
loBitmap.Save("c:\flies\test.bmp", _SCREEN.SYSTEM.drawing.Imaging.ImageFormat.png)
Two more points you may want to consider.

You may skip the temporary icon files by loading the bitmap directly from the Icon handle (method .FromHicon(m.hIcon)).

I don't know if you're doing this in your production code, but you may (and should) free the icon handle after it is no longer needed.

Hope that this helps somehow. If you make other advances on this I would appreciate if you share them, as I'm not yet comfortable with the robustness of the solution.

>Hi folks,
>
>Based on the file extension, I am getting an icon file from SHGetFileInfo:
>
>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))
>
>
>Then to get the icon file, I save it as png file:
>
>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)
>
>
>Now the strange thing is, that the background of the image is black instead of white (see attachment). So I wonder if there is a way to change the background, which I doubt, because it's a bitmap, with the black background it doesn't look very good. Perhaps someone has an idea?
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform