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.
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);
您可以使用BitmapImage.StreamSource直接从Stream创建BitmapImage,而无需使用GDI +( System.Drawing
)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.