I have a Tiff file tha开发者_StackOverflowt comes from a scanner. It has a resolution of 300 dpi to start with. But later I need to change it to a different value, say 100.
What's the best way to do this without losing the initial compression and color depth?
I already tried opening the Tiff with Bitmap.FromFile()
, but I get an OutOfMemoryException
, also used the FreeImage library, but here, if the Tiff is grayscale, it always uses LZW compression instead of JPEG. I know LZW is better, but JPEG is mandatory for me.
When you change the resolution, do you want the image to still be the same size in inches? Or when you go to 100, are you expecting that the 300 pixels will now span 3 inches.
If you want it to be the same size, then you must resample the image to a smaller number of pixels (1/3). In this case, you must decode the image, resample it, then re-encode it. You will certainly lose information in the resample, and then you lose will more with the lossy JPEG compression that TIFF supports.
If you mean for the image to now appear to be 3 times larger, then you might be able to do this by editing just the MetaData of the TIFF. The actual pixel data doesn't have to be touched to change the resolution. libtiff can do this -- I don't know if LibTiff.NET can, but probably.
If you are looking at commercial solutions, my company's DotImage Document Imaging can also do this.
The OutOfMemoryException
is because .NET doesn't support TIFF with JPEG compression. See this answer for more.
精彩评论