• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4427
  • Last Modified:

How to reduce file size of an existing tiff image without losing too much quality?

Hi experts,

ich have a scanned tiff formatted image, that has a large size. This the size is about 12 MB. How to reduce this size using c#?

Here is my code, I have, but that does not change anything of the image:

ImageCodecInfo codecInfo = ImageCodecInfo.GetImageEncoders().First(c => c.MimeType.ToUpperInvariant() == "image/tiff".ToUpperInvariant());
EncoderParameters encParams = new EncoderParameters(1);
encParams.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW);

Bitmap bmp = new Bitmap(e.PageInfo.Stream);
using (MemoryStream imageData = new MemoryStream())
	bmp.Save(imageData, codecInfo, encParams);
	//Do something with the new Image stream

Open in new window

  • 2
  • 2
1 Solution
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:

Have you tried converting TIFF to JPEG and convert back to TIFF?
Not sure how much quality is lost in this approach but give it a try.
check the first reply- http://social.msdn.microsoft.com/Forums/vstudio/en-US/f2838678-8525-4ad1-94d2-93c23b57d12a/how-to-compress-tif-image-file-using-c?forum=csharpgeneral

If the TIFF file has same resolution then you can try resizing with this solution-
kankmanAuthor Commented:
Hi rikin_shah,

My code is from the first link you've provided. That has no effect.
The second link is only a resizing of the image by height or width. The resolution should stay as it is. I scanned the image using 400 dpi. After scanning I give the image to an ocr software. And this needs best quality.

I also used a scanner, that costs about 25.000€, and the resolution is great, but the color of the image is not soooo great. But the image seems sharper (at the same dpi as the desktop scanner I use).

I think the expensive Scanner does something with the image data to reduce the size.

By the way: The scan settings I use are both the same. What kind of compression could it use to compress an image taken with my desktop scanner (800 €, 50MB file size) to about 1 MB file size?
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:

Have you tried conversion to PNG? Or does your scanner give only TIFF outputs? Is tiff a compulsion or any other filetype is supported with OCR?

You can try converting TIFFs to PNGs if they give you a good results with same/little lesser quality.

System.Drawing.Bitmap.FromFile("your image.tif").Save("your image.png", System.Drawing.Imaging.ImageFormat.Png);

Open in new window

Also, try reducing the quality with below and check if it satisfies your needs-
kankmanAuthor Commented:
Thanks for the info. The problem was solved by two facts:

The file I saved was saved using: Image.Save(...).
This uses the LZW-Compression method. Saving the Stream into a file, without using Image.Save AND reducing the quality A LITTLE BIT made it from 20-30 MB down to 900KB.

Thanks for the advises.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now