任何使TiffBitmapEncoder更快的方法?

时间:2013-06-24 18:10:20

标签: c# wpf image-processing

我有一个将原始图像转换为tif的方法。安装了原始图像的编解码器:

private void SaveTiff(string filename, string output)
{
    try
    {
        System.Windows.Media.Imaging.BitmapDecoder bmpDec = System.Windows.Media.Imaging.BitmapDecoder.Create(new Uri(filename), System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreColorProfile, System.Windows.Media.Imaging.BitmapCacheOption.None);

        System.Windows.Media.Imaging.BitmapSource srs = bmpDec.Frames[0];

        if (Path.GetExtension(output).Equals(".tif", StringComparison.CurrentCultureIgnoreCase))
        {
            using (FileStream stream = new FileStream(output, FileMode.Create))
            {
                System.Windows.Media.Imaging.TiffBitmapEncoder encoder = new System.Windows.Media.Imaging.TiffBitmapEncoder();
                encoder.Compression = System.Windows.Media.Imaging.TiffCompressOption.None;
                encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(srs));
                encoder.Save(stream);
            }

        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.ToString());
    }   
}

工作正常。但是,图像大小为4928x3264,48bppRGB。在普通PC(16GB,4核,3.1GHZ)上转换需要20多秒。有没有办法让它更快? colordepth和dpi可以更改,但tif必须是未压缩的。我试图改变colordepth,dpi,甚至大小,它仍然需要大约相似的时间。我猜,这是因为它必须首先解码原始图像,因为编解码器需要时间。它是否正确?还有其他建议吗?

当我们使用BitmapImage时,我们可以使用DecodePixelWidth来节省内存,可能是时间,是否有BitmapSource的siilar方法/属性(我使用的是什么)?

由于

0 个答案:

没有答案