Show Bitmap in WPF DataGrid

Jul 9, 2009 at 6:38 AM


I have a WPF datagrid with image control template column in which I want to display an image comming from the binding collection (Bitmap Image and string Displayname).

Image property of the collection (Bitmap Image) is a System.Drawing.Bitmap type

So, my problem is, how to show this Bitmap image (System.Drawing.Bitmap) in my image control

Thanks & Regards,





Jul 9, 2009 at 8:51 AM

try to use this helper function:


public static BitmapSource BitmapSourceFromImage(System.Drawing.Image img)
            MemoryStream memStream = new MemoryStream();

            // save the image to memStream as a png
            img.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);

            // gets a decoder from this stream
            System.Windows.Media.Imaging.PngBitmapDecoder decoder = new System.Windows.Media.Imaging.PngBitmapDecoder(memStream,        System.Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat, System.Windows.Media.Imaging.BitmapCacheOption.Default);

            return decoder.Frames[0];

Jul 9, 2009 at 11:11 AM

Thanks, Its woking fine