I have a tiff file which during original creation and saving has compression type "LZW".
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000);
Graphics g = Graphics.FromImage(bitmap);
fileName = saveDirectory + id + ".tif";
bitmap.Save(fileName, ImageFormat.Tiff);
So I am trying to change its compression to CCIT:-
Bitmap myBitmap;
myBitmap = new Bitmap(fileName);
ImageCodecInfo myImageCodecInfo;
myImageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder myEncoder;
myEncoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters myEncoderParameters;
myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter;
myEncoderParameter = new EncoderParameter(myEncoder,(long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
myBitmap.Save(new_fileName);
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
However, after running through the process, my file properties still says that it is of the "LZW compression" type.
Can anyone explain to me where I am going wrong with this?
The Tagged Image File Format (TIFF) is widely popular, and is particularly used in document imaging. It can support a number of compression types: Packbits – Created by Apple, this lossless compression type is used for run-length encoding (RLE). Baseline TIFF readers must support this compression.
Both LZW and ZIP will give good results. Use either with confidence. For 16-bit TIFF files, use ZIP.
TIFF files are much larger than JPEGs, but they're also lossless. That means you lose no quality after saving and editing the file, no matter how many times you do it. This makes TIFF files perfect for images that require big editing jobs in Photoshop or other photo editing software.
Change your last line to:
myBitmap.Save(new_fileName, myImageCodecInfo, myEncoderParameters);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With