Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Issue with icon file
Message
From
06/04/2020 18:35:42
 
 
To
06/04/2020 06:27:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01673979
Message ID:
01673997
Views:
91
This message has been marked as the solution to the initial question of the thread.
Christian, a re-reply.

Found a hint to draw the icon into a bitmap, instead of convert it.

Where relevant, your code could changed into this:
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.

>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
Next
Reply
Map
View

Click here to load this message in the networking platform