开发者

Wpf adding dynamic bitmap to an image

开发者 https://www.devze.com 2023-02-20 12:47 出处:网络
I\'m having problems adding an image I just created but which is not stored at a location like\"C:...\"

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消