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

kankmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Hi,

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-
http://stackoverflow.com/questions/3885395/how-to-reduce-the-size-of-an-image-in-c-sharp-and-net-3-5
0
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?
0
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Hi,

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.

Try-
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-
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder.quality.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.