kartal
kartal

Reputation: 18096

display bitmap value in image control

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

Upvotes: 4

Views: 8241

Answers (3)

ChrisWue
ChrisWue

Reputation: 19060

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}/>

Upvotes: 1

BrokenGlass
BrokenGlass

Reputation: 161002

Convert the bitmap to a BitmapImage and assign it to the property (i.e. 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;

Upvotes: 2

user203570
user203570

Reputation:

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}"/>

Upvotes: 1

Related Questions