|
-
Oct 18th, 2011, 06:06 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Converting bitmap to bitmapimage
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?
-
Oct 18th, 2011, 06:39 AM
#2
Re: Converting bitmap to bitmapimage
Moved From The CodeBank (which is for sharing code with others rather than posting questions )
-
Oct 18th, 2011, 07:00 AM
#3
Re: Converting bitmap to bitmapimage
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
-
Oct 18th, 2011, 12:14 PM
#4
Thread Starter
Addicted Member
Re: Converting bitmap to bitmapimage
 Originally Posted by boops boops
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
Thanks, Boops! This works great
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|