Search code examples
c#freeimage

How to convert TIFF to JPEG?


I am trying to convert a TIFF file to JPEG using FreeImage.

The problem is that FreeIamge.SaveToStream doesn't actually do anything. Even after the call, stream has a Length, Capacity and Position of 0.

This is my code:

using (var stream = new MemoryStream())
{
    var image = FreeImage.LoadEx(fileName);
    FreeImage.SaveToStream(image, stream, FREE_IMAGE_FORMAT.FIF_JPEG,
                           FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB);

    // stream.Length, stream.Capacity & stream.Position are all 0 here
}

What am I doing wrong?


Solution

  • The problem was the input - a 16 bit image created by another image library. It looks like FreeImage has some problems with 16 bit images as GDI+ could read it without problems. I switched the input to a 24 bit image and the code in my question started working.