Reputation: 381
I'm trying to convert a JPG
file to TIFF
using
System.Drawing.Image.Save(String, ImageFormat)
but the resulting TIFF
is 4 times the files ize of the JPEG
. For example, a 200KB JPEG
results in a 800KB TIFF
.
How can I get a TIFF
file or roughly the same size as the JPEG
?
Upvotes: 1
Views: 2801
Reputation: 1660
If you absolutely need to convert a JPEG to a TIFF. You can try using the overloaded method Image.Save Method (Stream, ImageCodecInfo, EncoderParameters)
You'll need to pass in an encoder parameter that has compression set to JPEG.
This MSDN link has an example on how to set/use encoder parameters.
Based on this quote from Wikipedia you should be able to save the TIFF with about the same file size.
A TIFF file, for example, can be a container holding JPEG (lossy) and PackBits (lossless) compressed images
EDIT: Just tried using GIMP (open source image editing program) and saved a JPEG as a TIFF but used different settings for compression. Below are the results:
Original JPEG file: 256KB
TIFF file with JPEG compression: 598KB
TIFF file with LZW compression: 2,239KB
It looks like even if you end using the JPEG compression algorithm for the TIFF file, your file size might double. I'm not sure if this is just the program/image I used that gave me these results since I didn't try anything else, but at least I didn't get 4X the original size.
On the other hand, JPEG compression doesn't appear to be an option in the System.Drawing.Imaging.EncoderValue
enum. So maybe try each of the available options and see if they work, or find some other library that may be able to do this. Maybe try LibTiff?
Upvotes: 5
Reputation: 1
A jpeg file is compressed and does not have the complete data of tiff. A tiff file is always much bigger than a jpeg file. The base format for Photoshop tiff. The Brandon answer is very good also.
Upvotes: 0