Reputation: 1989
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?
Upvotes: 9
Views: 14807
Reputation: 9407
Change your last line to:
myBitmap.Save(new_fileName, myImageCodecInfo, myEncoderParameters);
Upvotes: 12