我有一个tiff文件,在原始创建和保存期间有压缩类型“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);
所以我试图将其压缩改为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;
}
但是,在完成该过程后,我的文件属性仍然表示它是“LZW压缩”类型.
任何人都可以向我解释我在哪里出错吗?
解决方法:
将您的最后一行更改为:
myBitmap.Save(new_fileName, myImageCodecInfo, myEncoderParameters);