User Tools

Site Tools


creating_20a_20png_20file_20from_20a_20windows_20icon

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

creating_20a_20png_20file_20from_20a_20windows_20icon [2018/03/31 13:19]
127.0.0.1 external edit
creating_20a_20png_20file_20from_20a_20windows_20icon [2018/04/13 14:59] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Creating a PNG file from a Windows icon===== =====Creating a PNG file from a Windows icon=====
  
-//by Richard Russell, February 2018//\\ \\  Both Windows icons and PNG (Portable Network Graphics) files support transparency - an alpha channel if you prefer - so it may be useful to convert the former to the latter. For example Android and Mac OS icons use PNG format, so if you want to convert a Windows icon to be suitable for those operating systems this is what you need. The **PROCpngfromhicon()** procedure listed below performs the required conversion; its parameters are the path and filename of the PNG file to be created, a handle to the icon and the width and height of the icon (the routine could have discovered the dimensions itself, but in the program for which it was written they were already known). If you need to resize the icon the **CopyImage** API will do that.\\ \\  The procedure has a dependency on GDIPlus so you will need to include this code in the initialisation section of your program:\\ \\ +//by Richard Russell, February 2018//\\ \\  Both Windows icons and PNG (Portable Network Graphics) files support transparency - an alpha channel if you prefer - so it may be useful to convert the former to the latter. For example Android and Mac OS icons use PNG format, so if you want to convert a Windows icon to be suitable for those operating systems this is what you need. The **PROCpngfromhicon()** procedure listed below performs the required conversion; its parameters are the path and filename of the PNG file to be created, a handle to the icon and the width and height of the icon (the routine could have discovered the dimensions itself, but in the program for which it was written they were already known). If you need to resize the icon the **CopyImage** API will do that.\\ \\  The procedure has a dependency on GDIPlus so you will need to include this code in the initialisation section of your program: 
 + 
 +<code bb4w> ​
         INSTALL @lib$ + "​GDIPLIB"​         INSTALL @lib$ + "​GDIPLIB"​
         PROC_gdipinit         PROC_gdipinit
Line 7: Line 9:
         SYS "​GetProcAddress",​ gdip%, "​GdipCreateBitmapFromScan0"​ TO `GdipCreateBitmapFromScan0`         SYS "​GetProcAddress",​ gdip%, "​GdipCreateBitmapFromScan0"​ TO `GdipCreateBitmapFromScan0`
         SYS "​GetProcAddress",​ gdip%, "​GdipSaveImageToFile" ​      TO `GdipSaveImageToFile`         SYS "​GetProcAddress",​ gdip%, "​GdipSaveImageToFile" ​      TO `GdipSaveImageToFile`
-\\  ​and this code should be executed on exit:\\ \\ +</​code>​ 
 + 
 +and this code should be executed on exit: 
 + 
 +<code bb4w>
         PROC_gdipexit         PROC_gdipexit
-\\  ​Here is the procedure itself:\\ \\ +</​code>​ 
 + 
 +Here is the procedure itself: 
 + 
 +<code bb4w>
         DEF PROCpngfromhicon(png$,​ hicon%, w%, h%)         DEF PROCpngfromhicon(png$,​ hicon%, w%, h%)
         LOCAL I%, bitmap%, wide%, ole32%, cfs%         LOCAL I%, bitmap%, wide%, ole32%, cfs%
Line 54: Line 64:
         SYS "​FreeLibrary",​ ole32%         SYS "​FreeLibrary",​ ole32%
         ENDPROC         ENDPROC
 +</​code>​
creating_20a_20png_20file_20from_20a_20windows_20icon.txt · Last modified: 2018/04/13 14:59 by richardrussell