當我旋轉圖像時,.Net切換tiff編碼。有沒有辦法讓我保持CCITT傳真4(組4傳真編碼),而不是將它切換到LZW?這是我如何旋轉磁盤上的圖像。.Net Image.Save將CTTIT傳真4中的tiff更改爲LZW
System.Drawing.Image img = System.Drawing.Image.FromFile(input);
//rotate the picture by 90 degrees
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
img.Save(input, System.Drawing.Imaging.ImageFormat.Tiff);
感謝, 布賴恩
更新:這是基於鏈接下面的文章中的代碼。我想在這裏添加完整的代碼。此外,我設置水平分辨率,因爲位圖默認爲96 DPI。
//create an object that we can use to examine an image file
System.Drawing.Image img = System.Drawing.Image.FromFile(input);
//rotate the picture by 90 degrees
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
// load into a bitmap to save with proper compression
Bitmap myBitmap = new Bitmap(img);
myBitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
// get the tiff codec info
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID for the Compression parameter category
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Compression;
// create encode parameters
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
// save as a tiff
myBitmap.Save(input, myImageCodecInfo, myEncoderParameters);
// get encoder info for specified mime type
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;
}
感謝的作品。它將DPI從300改爲96。有人知道如何設置它嗎? – BrianK 2010-12-23 17:22:55