2

我正在尝试将多个.tif文件合并为一个,但合并后,新.tif文件的图像质量非常低。

如何提高这种质量?

我希望新合并的文件质量为原始质量。我正在使用此代码合并 tif 文件

   string[] sa = path;
        ImageCodecInfo info = null;
        foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
            if (ice.MimeType == "image/tiff")
                info = ice;
        Encoder enc = Encoder.SaveFlag;
        EncoderParameters ep = new EncoderParameters(1);
        ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
        Bitmap pages = null;
        int frame = 0;
        foreach (string s in sa)
        {
            //  using (FileStream fileStream = System.IO.File.Open(s, FileMode.Open))
            {
                if (frame == 0)
                {
                    pages = (Bitmap)Image.FromFile(s);
                    //save the first frame
                    pages.Save(filepath, info, ep);
                }
                else
                {
                    //save the intermediate frames
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);
                    Bitmap bm = (Bitmap)Image.FromFile(s);
                    pages.SaveAdd(bm, ep);
                }
                if (frame == sa.Length - 1)
                {
                    //flush and close.
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
                    pages.SaveAdd(ep);
                }
                frame++;
            }
        }
4

1 回答 1

0

不是 100% 确定这一点,但我相信 Multi-Frame TIFF 默认使用 G3 编码。只是给一些尝试,改变这个:

Encoder enc = Encoder.SaveFlag;
EncoderParameters ep = new EncoderParameters(1);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);

对此:

Encoder enc = Encoder.SaveFlag;
Encoder encComp = Encoder.Encoder.Compression;
EncoderParameters ep = new EncoderParameters(2);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
ep.Param[1] = new EncoderParameter(encComp, (long)EncoderValue.CompressionLZW);

再试一次(你也可以使用CompressionNone代替CompressionLZW,但 LZW 是无损的,所以它不应该降低质量)

于 2015-01-08T13:15:54.617 回答