gpt4 book ai didi

c# - 压缩多帧 Tiff

转载 作者:行者123 更新时间:2023-11-30 17:47:45 26 4
gpt4 key购买 nike

我目前正在生成多个图像并将它们保存到多帧 tiff。

我正在使用这段代码来保存 tiff。

System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.SaveFlag;
ImageCodecInfo encoderInfo = ImageCodecInfo.GetImageEncoders().First(i => i.MimeType == "image/tiff");
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);

// Save the first frame of the multi page tiff
Bitmap firstImage = (Bitmap)_imageList[0];
firstImage.Save(System.IO.Directory.GetCurrentDirectory() + @"\ChargeInvoice Images\" + OrderNumber + "_Invoice.tiff", encoderInfo, encoderParameters);

encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);

// Add the remining images to the tiff
for (int i = 1; i < _imageList.Count; i++)
{
Bitmap img = (Bitmap)_imageList[i];
firstImage.SaveAdd(img, encoderParameters);
}

// Close out the file
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
firstImage.SaveAdd(encoderParameters);

一些 tiffs 超过 18 页,文件大小超过 11 MB。

有没有一种方法可以压缩 tiff 以节省尺寸?

如果我失去一些图像质量也没关系。

最佳答案

添加一个EncoderParam用于压缩:

System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.SaveFlag;
System.Drawing.Imaging.Encoder compressionEncoder = System.Drawing.Imaging.Encoder.Compression;

EncoderParameters encoderParameters = new EncoderParameters(2);
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
encoderParameters.Param[1] = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionLZW);

关于c# - 压缩多帧 Tiff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24331562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com