IO.Stream for image in WPF

I am trying to read an image from a resource dll file. I can read the image and image name, but how to set the Image control for the stream? In the window 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?

+6
source share
2 answers

In WPF, you probably have an Image element in your xaml. Source can be any BitmapImage . You can associate BitmapImage with a ViewModel where you can create an instance from Stream , for example this .

+3
source

In WPF, you can set the Source property for 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 an array of bytes with the image source.

+13
source

Source: https://habr.com/ru/post/946259/


All Articles