2007-12-10

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.


 


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.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
    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


 

2 comments:

  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.

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


    -- Convertir BMP a ICONO - Parte 3 --

    http://www.portalfox.com/article.php?sid=2542

    ReplyDelete