Below are 4 simple ways to convert a BMP to ICON, using GdiPlusX.
Those 2 blog posts were before we updated the library, adding the support for saving Icons with good quality.
This sample uses 4 techniques, and creates 4 versions of ICONS from the same image file.
Before the conversion, it resizes the source image to the size of 16x16. This means that with this sample you can convert any image to ICO file.
In the next release, we hope to deliver a complete solution for .ICO files too, with very simplified code, offering great ICO files support, that is not present in the .NET version, thanks to Carlos Alloatti.
IMPORTANT
Requires VFP9 and GdiPlusX to run.
Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently.
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home
Do Locfile("system.prg")
With _Screen.System.Drawing As xfcDrawing * Convert the original bitmap to ensure better quality and compatibility
loResized = .Bitmap.New(.Bitmap.FromFile(Getpict()), 16,16)
* Create Icon Object
Local loIcon As xfcIcon
loIcon = .Icon.FromHandle(loResized.GetHicon())
*** LOW QUALITY ICONS
* Save sending FileName
loIcon.Save("c:\Icon_Save_FileName_LowQual.ico")
* Save Using Stream
Local loStream As xfcMemoryStream
loStream = _Screen.System.IO.MemoryStream.New()
loIcon.Save(loStream)
Strtofile(loStream.GetBuffer(), "c:\Icon_Save_Stream_LowQual.Ico")
*** HIGH QUALITY ICONS
*** Setting the tlQuality flag to .T.
* Save sending FileName
loIcon.Save("c:\Icon_Save_FileName_HighQual.ico", .T.)
* Save Using Stream
Local loStream2 As xfcMemoryStream
loStream2 = _Screen.System.IO.MemoryStream.New()
loIcon.Save(loStream2, .T.)
Strtofile(loStream2.GetBuffer(), "c:\Icon_Save_Stream_HighQual.Ico")
Endwith