anti
anti

Reputation: 3135

WPF loading a BitmapImage into an image programatically

I am trying to load an image into an Image control in a WPF application.

I need to set the Input in one function, and bind it to the Image in another.

This works:

var b = new Binding { Source = (ImageSource)new ImageSourceConverter().ConvertFromString("D:/data/TestPattern.jpg") };
CameraFrame.SetBinding(Image.SourceProperty, b);

But this does not:

BitmapImage bSource = new BitmapImage(new Uri("D:/data/TestPattern.jpg"));
var b = new Binding { Source = (ImageSource)new ImageSourceConverter().ConvertFrom(bSource) };

CameraFrame.SetBinding(Image.SourceProperty, b);

Why is this? Am I missing something in the ConvertFrom function?

Upvotes: 0

Views: 445

Answers (1)

mm8
mm8

Reputation: 169400

Why don't you simply set the Source property to a BitmapImage?

CameraFrame.Source = new BitmapImage(new Uri("D:/data/TestPattern.jpg"));

Upvotes: 1

Related Questions