_Gdiplus.vcx and SavetoFile

Do you see something wrong in the code below ?

local lcsource, lcdest
lcsource = getpict()
lcdest = justpath(lcsource) + "\_" + juststem(lcsource)

local loimage as gpimage of home() + ffc/_gdiplus.vcx
loimage = newobject("gpimage",home()+"ffc/_gdiplus.vcx")
loimage.savetofile(lcdest + ".png","image/png")

That's a very simple code, that is supposed to load an image and save it as a png. But nothing happens ! Can you guess why ???

The Savetofile method from gpimage class from _gdiplus.vcx must receive as a required second parameter, the "tvclsidencoder", that can be the clsid of the encoder to use, or a MIME type, eg "image/jpeg" or "image/png". If a MIME type is specified, then the method dynamically looks up the clsid of the appropriate encoder.

99% of us pass the mime type, because that's easier to remember, but be careful ! Because that parameter mime type, is case sensitive !

You have always to pass this parameter in lowercase !

The code above did not work because i typed "image/png" instead of "image/png".

Man, i've lost a lot of time to find that !



By the way, the MIME (multipurpose internet mail extensions) types of the encoders built into microsoft windows gdi+ are as follows:

  • image/bmp

  • image/jpeg

  • image/gif

  • image/tiff

  • image/png



No comments:

Post a Comment