如何快速将BitmapSource转换为位图?

时间:2011-12-18 23:57:18

标签: .net-4.0

任何人都可以建议一种方法将2352x1726x8bit灰度BitmapSource转换为Bitmap,比3.2GHz P4上的速度大约600ms更快:

    public static Bitmap toBitmap(this BitmapSource bitmapsource)
    {
        Bitmap bitmap;
        using (MemoryStream stream = new MemoryStream())
        {
            // from System.Media.BitmapImage to System.Drawing.Bitmap 
            PngBitmapEncoder enc = new PngBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create(bitmapsource));
            enc.Save(stream);
            bitmap = new System.Drawing.Bitmap(stream);
        }
        return bitmap;
    }

0 个答案:

没有答案