我有一个位图,我想在图像控制中显示它而不保存它,我该怎么做?
Convert the bitmap to a BitmapImage
and assign it to the property (ie in the example CurrentImage
) the image control's Source
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;
In what way do you have the bitmap? If you a BitmapImage
, just set the Image.Source dependency property.
BitmapImage bitmap = ... // whatever
Image image = new Image();
image.Source = bitmap;
In XAML you can set it to something on disk also, or bind it.
<Image Source="myimage.bmp"/>
// Or ...
<Image Source="{Binding Path=PropertyInMyViewModel}"/>
A BitmapImage
can take an uri as parameter:
BitmapImage MyImage = new BitmapImage(someuri);
and then you can bind your image control to it
<Image Source={Binding MyImage}/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.