C# 在Windows 8应用商店应用中将ImageBrush.ImageSource设置为Image

C# 在Windows 8应用商店应用中将ImageBrush.ImageSource设置为Image,c#,windows-store-apps,imagebrush,C#,Windows Store Apps,Imagebrush,我的C#代码中有一个图像对象,我想将其用作ImageBrush的ImageSource。 有办法做到这一点吗 换句话说,我需要这样的东西: Image image = new Image(); image.source = GetBitmapImage(); //execute various image transforms here... ImageBrush imageBrush = new ImageBrush(); imageBrush.ImageSource = image;

我的C#代码中有一个图像对象,我想将其用作ImageBrush的ImageSource。 有办法做到这一点吗

换句话说,我需要这样的东西:

Image image = new Image();

image.source = GetBitmapImage();

//execute various image transforms here...

ImageBrush imageBrush = new ImageBrush();

imageBrush.ImageSource = image; // this doesn't work

谢谢。

您已经有了
ImageSource
-它是您的
GetBitmapImage()
,因此您可以使用

 ImageBrush imageBrush = new ImageBrush(GetBitmapImage());
或者使用您的图像。来源:

imageBrush.ImageSource = image.source;

ImageSource
属性设置为类型。因此,必须提供从
Windows.UI.Xaml.Media.ImageSource
派生的对象

对象“image”的类型为
Windows.UI.Xaml.Controls.image
,它不是从
ImageSource
类型派生的

但是,您的方法
GetBitmapImage()
返回一种类型的
ImageSource
,因此您可以在完成修改后调用下面的代码

imageBrush.ImageSource=image.Source

干杯