Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert TIFF to JPEG?

Tags:

c#

freeimage

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?

like image 965
Daniel Hilgarth Avatar asked Nov 11 '22 01:11

Daniel Hilgarth


1 Answers

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.

like image 184
Daniel Hilgarth Avatar answered Nov 14 '22 21:11

Daniel Hilgarth