Associate dynamically created Bitmap object with image in WPF

I have a bitmap object that is not a static resource. Typically, with image binding in WPF, you can snap to a string path. However, I do have a dynamically created bitmap object that I would like to snap to. Is it possible to do something like:

<WrapPanel x:Name="imageWrapPanel" HorizontalAlignment="Center"> <Image Source="{Binding Material1}" Margin="10" /> <Image Source="/NightVision;component/Images/concrete_texture.tif" Margin="10" /> </WrapPanel> 

And in the code behind the file, I have a public accessor:

 public Bitmap Material1 { get { return new Bitmap(/* assume created somewhere else*/) } } 

Above obviously doesn't work, is there a way to do something like this?

+4
source share
2 answers

A similar question has already been given .. using ValueConverters .. check this:

WPI Image UriSource Image and Data Binding

+3
source

The only thing you need to do is convert the Bitmap to an ImageSource that you can use in the Image control. So in your binding you can add a Converter that will do this. The implementation of the conversion is likely to be found in the answers to this question .

(If you have the option of working directly with BitmapImage (WPF) instead of Bitmap (WinForms), this might be a good idea)

+3
source

All Articles