10

I am trying to read an image from a resource only DLL file. I am able to read the image name and image bytes, but How do I set the Image control to stream buffer? In windows form, I know I can use this :

pictureBox1.Image=new System.Drawing.Bitmap(IOStream);

since there is no Drawing namespace in wpf, how can I achieve the same thing?

1
  • Yes there is, just add the reference to System.Drawing.dll using the VS "Add Reference" dialog May 31, 2013 at 12:30

2 Answers 2

20

In WPF, you can set the Source property of an Image, as in this example:

Image image = new Image();
using (MemoryStream stream = new MemoryStream(byteArray))
{
    image.Source = BitmapFrame.Create(stream,
                                      BitmapCreateOptions.None,
                                      BitmapCacheOption.OnLoad);
}

Where byteArray is the array of bytes with the source of the image.

2
  • @TanujWadhwa Sorry, I misunderstood the question, edited to reflect this. May 31, 2013 at 12:47
  • 1
    what I was looking for.
    – HXD
    Oct 2, 2015 at 18:37
5

In WPF you probably have an Image element in your xaml. The Source can be any BitmapImage. You can bind a BitmapImage from your ViewModel, where you can create an instance from a Stream like this.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.