Reputation: 3462
I have an Image object in my C# code and I'd like to use it as ImageSource for ImageBrush. Is there a way to do this?
In other words, I need something like this:
Image image = new Image();
image.source = GetBitmapImage();
//execute various image transforms here...
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = image; // this doesn't work
Thanks.
Upvotes: 1
Views: 2223
Reputation: 12683
The ImageSource
property is set to type of Windows.UI.Xaml.Media.ImageSource
. Therefore you must provide an object that derives from Windows.UI.Xaml.Media.ImageSource
.
Your object "image" is of type Windows.UI.Xaml.Controls.Image
which is not derrived from the ImageSource
type.
However, your method GetBitmapImage()
returns a type of ImageSource
so you can call the code below after you have finished your modifications.
imageBrush.ImageSource = image.Source;
Cheers.
Upvotes: 1
Reputation: 10376
You already have ImageSource
- it is your GetBitmapImage()
, so you can use
ImageBrush imageBrush = new ImageBrush(GetBitmapImage());
or use your image.source:
imageBrush.ImageSource = image.source;
Upvotes: 0