Display bitmap value in image management

I have a bitmap and want to display it in the image management without saving it, how can I do this?

+4
source share
3 answers

Convert the bitmap image to BitmapImage and assign it to a property (i.e. in the CurrentImage example), the image control property is bound to:

 MemoryStream ms = new MemoryStream(); _bitmap.Save(ms, ImageFormat.Png); ms.Position = 0; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); CurrentImage = bi; 
+2
source

How do you have a bitmap? If you are BitmapImage , just set the Image.Source dependency property .

 BitmapImage bitmap = ... // whatever Image image = new Image(); image.Source = bitmap; 

In XAML, you can also install it on disk or bind to it.

 <Image Source="myimage.bmp"/> // Or ... <Image Source="{Binding Path=PropertyInMyViewModel}"/> 
+1
source

A BitmapImage can take uri as a parameter:

 BitmapImage MyImage = new BitmapImage(someuri); 

and then you can attach your image control to it

 <Image Source={Binding MyImage}/> 
+1
source

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


All Articles