Convert to BitmapImage

Want to convert your KalikoImage (if your using C# Image Library) into a System.Windows.Media.Imaging.BitmapImage for use with for instance WPF, then here's your code (kalikoImage being your KalikoImage object):
MemoryStream ms = new MemoryStream();
kalikoImage.SaveBmp(ms);
ms.Position = 0;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();

If you instead want to convert a System.Drawing.Bitmap to a System.Windows.Media.Imaging.BitmapImage, then this is your code (myBmp being your Bitmap object):
MemoryStream ms = new MemoryStream();
myBmp.Save(ms, ImageFormat.Bmp);
ms.Position = 0;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();

Once you have your BitmapImage, you can pass that into a System.Windows.Controls.Image:
System.Windows.Controls.Image img = new System.Windows.Controls.Image();
img.Source = bi;

Related posts:

Comments

comments powered by Disqus