Wpf adding dynamic bitmap to an image
I'm having problems adding an image I just created but which is not stored at a location like"C:..."
So I was wondering if there was a way of adding that image to the wpf without it being needed to be first saved ....
Example of what I would of want.开发者_StackOverflow
Bitmap bit;
LoadBitmap(bit);
image = bit;
I've found a solution in Tamir Khason's blog here:
Using
public static BitmapSource ConvertBitmap(System.Drawing.Bitmap source)
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
source.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
you could do
Bitmap bit;
LoadBitmap(bit);
image.Source = ConvertBitmap(bit);
You can use BitmapImage.StreamSource to create a BitmapImage directly from a Stream, without using GDI+ (System.Drawing
).
精彩评论