Convert BMP to ICO - Part 3

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.


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.


do locfile("system.app")

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

* save using stream
    local lostream as xfcmemorystream
    lostream = _screen.system.io.memorystream.new()

    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")




  1. Excellent work, Cesar.

    As always with your coded examples, its very easy to implement.

    I'm looking forward to the .ico files.

    Will they have both 16x16 and 32x32?

    Keep up the good work! I'd like you to know your GDIplusx image handling developments are very much appreciated.

  2. Este articulo se encuentra traducido al español en www.PortalFox.com

    -- Convertir BMP a ICONO - Parte 3 --