1

I have a Tiff file that 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.

Alexandru Pupsa
  • 1,798
  • 4
  • 21
  • 40
  • Some points: First, `dpi` (dots per inch) is related to output, not pixels (and is frequently misused like this). The term you want when working strictly with an image is `ppi` (pixels per inch). Second, JPEG by definition is lossy whereas LZW is not. (Though there is a [lossless JPEG standard](http://en.wikipedia.org/wiki/Lossless_JPEG).) Third, changing the number of pixels in an image is termed `resampling` and when *reducing* the ppi of an image, you will always lose detail. – JYelton Mar 01 '11 at 16:54
  • possible duplicate of [To load .tiff file in C#](http://stackoverflow.com/questions/4265491/to-load-tiff-file-in-c) – JYelton Mar 01 '11 at 16:59
  • If you want to preserve compression, you can't decode the pixels with Bitmap.FromFile(). There is no way to get it back into JPEG form without losing quality. – Lou Franco Mar 02 '11 at 01:54
  • Can you post a link to a sample image? –  Mar 03 '11 at 16:06

2 Answers2

2

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.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
1

The OutOfMemoryException is because .NET doesn't support TIFF with JPEG compression. See this answer for more.

Community
  • 1
  • 1
JYelton
  • 35,664
  • 27
  • 132
  • 191