Menu

save metadatas in freeImage

Developers
valenza
2014-12-18
2014-12-20
  • valenza

    valenza - 2014-12-18

    When I use save to save metadatas with freeImage, if the 'filename' contains a path nothing is saved but if I use only the name without the path, the file is saved.

    here is the code :
    FreeImage.Save((FIF_BMP, resdib, Filename, FREE_IMAGE_SAVE_FLAGS.DEFAULT)

    Thank you for Help

    S. Valenza

     
  • valenza

    valenza - 2014-12-18

    I have found the error, if the file exits it cannot be overwritten.
    Freeimage don't throw any exception.

    S. Valenza

     
  • valenza

    valenza - 2014-12-18

    anyone know why my file is not overwritten ?

    Thanks

     
  • Carsten Klein

    Carsten Klein - 2014-12-18

    Hi,

    according to my experiences, FreeImage is able to overwrite files. Maybe this is an access rights issue? Is the file locked by another process while FreeImage tries to overwrite it?

    Set a breakpoint right before you call the Save method and try to open the old image file with an (hex) editor, change some bytes and try to save it again (in the (hex) editor, not with FreeImage.Save, of course). I just want to see, if the file is locked while you try to overwrite it with FreeImage.

    Carsten

     
  • valenza

    valenza - 2014-12-18

    Hi,

    When my file is open and i try to modify it, it tell me that that i cannot access it.
    It seems like your remark is right.

    But how can I solve it ?
    do you think creating a différent process for the save function is a solution ?

    Thank you

    S. valenza

     
  • Carsten Klein

    Carsten Klein - 2014-12-18

    Hi,

    could you please post some more lines of your code? I'm interested in the lines at which you load the image.

    Carsten

     
  • valenza

    valenza - 2014-12-19

    HI,

    here is the code :

    dim resdib As FIBITMAP = New FIBITMAP()
    Dim fib As FreeImageBitmap = New FreeImageBitmap(filename)
    Dim plug As FreeImagePlugin = PluginRepository.Plugin(fib.ImageFormat)
    dim b as boolean
    PB.image = fib ' Picturebox
    resdib = FreeImage.CreateFromBitmap(fib)
    b = FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, resdib, filename, FREE_IMAGE_SAVE_FLAGS.DEFAULT)

    When I save the file, it seems like Picturebox image conflict with the freeimage bitmap...

    Thanks

    Valenza

     
  • Carsten Klein

    Carsten Klein - 2014-12-20

    Hi,

    although my former employee implemented the FreeImage .NET wrapper, it took me some time to get some answers on this (in my company, .NET is used very rarely).

    The problem is, that you are using the FreeImageBitmap class. This class opens a FileStream for the loaded image, which is left open, until the FreeImageBitmap class is disposed. That's why you can't overwrite the file.

    Why don't we close the stream after the image has been loaded? The FreeImageBitmap class was intended to be a drop-in replacement for the .NET Bitmap class and so, also supports multi-page images as well as single-page ones. In order to support appending and removing pages as well as saving the image as System.Drawing.Bitmap does, we had to leave the stream open. That's only the short story of a topic, I'm really no longer in...

    There are several solutions:

    1. You could use FreeImage.LoadEx(filename) instead of New FreeImageBitmap(filename). This gives you a FIBITMAP, which you can turn into a real System.Drawing.Bitmap with method FreeImage.GetBitmap(...). FreeImage.LoadEx does not rely on a FileStream (AFAIK).

    2. Another solution is to create (File)Stream object yourself and call any of the constructors of the FreeImageBitmap class, that take a Stream object. Then, you have ful control over the stream and can close it, before you save the new image. However, likely the FreeImageBitmap will not longer work as expected after the stream has been closed (you can't add some more pages to it).

    3. Dispose the FreeImageBitmap prior to saving the new image. Actually, you could even dispose the FreeImageBitmap directly after you've assigned it to the PictureBox. The PictureBox does not display the real FreeImageBitmap; the Bitmap has been converted to a System.Drawing.Bitmap while being assigned to the Image property of the PictureBox (implicit conversion by a conversion operator).

    Hope this helps.

    Carsten

     

Log in to post a comment.