How to convert tiff to jpeg?

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

The problem is that FreeIamge.SaveToStream actually does nothing. Even after the call, stream has Length , Capacity and Position 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?

+5
source share
1 answer

The problem was that the input is a 16-bit image created by another image library. It seems that FreeImage has some problems with 16-bit images, since GDI + can read it without problems. I switched the input to a 24-bit image and the code in my question started working.

+1
source

Source: https://habr.com/ru/post/1203135/


All Articles