1

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;

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, I don't get the error now. Time to work and make the dynamic work :P... Thanks
1

You can use BitmapImage.StreamSource to create a BitmapImage directly from a Stream, without using GDI+ (System.Drawing).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.