Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有什么方法可以让TiffBitmapEncoder更快?_C#_Wpf_Image Processing - Fatal编程技术网

C# 有什么方法可以让TiffBitmapEncoder更快?

C# 有什么方法可以让TiffBitmapEncoder更快?,c#,wpf,image-processing,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.Med

我有一个将原始图像转换为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());
    }   
}
它很好用。但是,图像大小为4928x326,48bppRGB。在普通PC(16GB,4核,3.1GHZ)上转换需要20秒以上。有没有办法让它更快?颜色深度和dpi可以更改,但tif必须解压缩。我试图改变颜色深度,dpi,甚至大小,但仍然需要相似的时间。我猜,这是因为它必须先解码原始图像,这需要时间,因为编解码器。这是正确的吗?还有其他建议吗

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


谢谢

您尝试过分析该代码吗?这通常会让你知道你的热点是什么我没有分析它,但基于调试,“encoder.Save(stream);”需要时间。如果将同一代码直接用于tif图像,则不需要花费时间。请尝试将其保存到
FileStream
中,而不是保存到
MemoryStream
中,然后查看这是否有区别。在这段代码下面是Windows映像组件,它通常非常快。我仍然强烈建议使用探查器,VS2010 Premium和更高版本,内置一个可以工作的探查器。