C# .Net图像。将更改tiff从CTTIT传真4保存到LZW

C# .Net图像。将更改tiff从CTTIT传真4保存到LZW,c#,tiff,C#,Tiff,旋转图像时,.Net会切换tiff编码。有没有办法让CCITT传真4(第4组传真编码)不切换到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.Imag

旋转图像时,.Net会切换tiff编码。有没有办法让CCITT传真4(第4组传真编码)不切换到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);
谢谢, 布莱恩

更新:以下是基于以下链接文章的代码。我想在这里为completenes添加代码。另外,我设置了水平分辨率,因为位图默认为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;
}
//创建一个可用于检查图像文件的对象
System.Drawing.Image img=System.Drawing.Image.FromFile(输入);
//将图片旋转90度
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
//加载到位图以进行适当压缩保存
位图myBitmap=新位图(img);
设置分辨率(img.水平分辨率,img.垂直分辨率);
//获取tiff编解码器信息
ImageCodecInfo myImageCodecInfo=GetEncoderInfo(“图像/tiff”);
//基于压缩参数类别的GUID创建编码器对象
System.Drawing.Imaging.Encoder myEncoder=System.Drawing.Imaging.Encoder.Compression;
//创建编码参数
EncoderParameters myEncoderParameters=新的EncoderParameters(1);
编码器参数myEncoderParameter=新的编码器参数(myEncoder,(long)EncoderValue.compressionCCIT4);
myEncoderParameters.Param[0]=myEncoderParameter;
//另存为tiff
保存(输入,MyImageCodeInfo,myEncoderParameters);
//获取指定mime类型的编码器信息
私有静态ImageCodeInfo GetEncoderInfo(字符串mimeType)
{
int j;
ImageCodeInfo[]编码器;
编码器=ImageCodecInfo.GetImageEncoders();
对于(j=0;j
Image类不会为您提供必要的粒度控件

为此,您需要读入位图,创建TIFF编码器,设置压缩类型的参数,然后让位图对象使用该编解码器和参数保存图像

下面是一个例子,可以引导您正确的方向:

目前我的Mac电脑上没有VS open

详情如下:


谢谢,这很有效。但它将DPI从300更改为96。有人知道如何设置吗?我认为image类确实支持这一点(至少它对我有用)。因此,您不需要使用额外的位图,而且作为额外的奖励,您也不需要乱弄分辨率。BrianK:bitmap.SetResolution()可以做到这一点(尽管这可能在两年后对您没有帮助!)