I'm trying to add a bitmap image to the source property of the Image control but can't find a way to convert the bitmap to bitmapimage. Is there any simple way do do this?
Printable View
I'm trying to add a bitmap image to the source property of the Image control but can't find a way to convert the bitmap to bitmapimage. Is there any simple way do do this?
Moved From The CodeBank (which is for sharing code with others rather than posting questions :) )
Hi Garry, you're in luck, I just got this figured out for myself. You can do it in code by saving the bitmap to an IO.MemoryStream as a PNG file and then using BitmapImage.StreamSource. Here's a VB.Net function as an example:
vb Code:
Private Function ToBitmapImage(img As System.Drawing.Image) As BitmapImage Dim ms As New IO.MemoryStream Dim bi As New BitmapImage img.Save(ms, System.Drawing.Imaging.ImageFormat.Png) bi.BeginInit() bi.StreamSource = ms bi.EndInit() Return bi End Function
Don't close the MemoryStream until you no longer need the BitmapImage.
BB