3

Can anyone suggest a way to convert a 2352x1726x8bit greyscale BitmapSource to Bitmap that is faster than the following taking about 600ms on a 3.2GHz P4:

    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;
    }
palacsint
  • 28,416
  • 10
  • 82
  • 109
ChrisJJ
  • 2,191
  • 1
  • 25
  • 38
  • I don't really have an answer to your question, but I would ask myself why I need this. `BitmapSource` is preferred over `Bitmap` now anyway. Obviously I don't know what you're doing or what your requirements are, but it's something you should consider. – Kir Feb 01 '12 at 14:28
  • 2
    Thanks but this is to interface with an existing library module that accepts BitMap and that I am not in a position to recode to use instead BitmapSource. – ChrisJJ Feb 09 '12 at 12:33
  • AForge, afaik, is a well-known library that needs `Bitmap`. – heltonbiker Sep 10 '13 at 19:13
  • This link seems to be relevant regarding your question: http://stackoverflow.com/questions/2284353/is-there-a-good-way-to-convert-between-bitmapsource-and-bitmap – Bombinosh Sep 20 '13 at 09:14

0 Answers0