0

I have a method that converts raw image to tif. the codec for raw image is installed:

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());
    }   
}

It works fine. However, the image size is 4928x3264 with 48bppRGB. It takes more than 20 seconds to convert on an average PC (16GB, 4 core, 3.1GHZ). Is there a way to make it faster? The colordepth and dpi can be changed, but the tif has to be uncompressed. I tried to change colordepth, dpi, and even size, it still takes about similar time. my guess, it is because it has to decode the raw image first, which takes time because of the codec. Is this correct? Any other suggestions?

When we use BitmapImage, we could use DecodePixelWidth to save memory, probably time, is there a siilar method/property for BitmapSource (which is what I use)?

Thanks

4

0 回答 0