[英]Convert BitmapImage to System.Windows.Media.Brush
How would I convert a BitmapImage to a System.Windows.Media.Brush
? 我如何将BitmapImage转换为System.Windows.Media.Brush
?
I have a BitmapImage imaginatively called bitmap
, and I have a Canvas (also imaginatively titled) canvas
. 我有一个想象地称为bitmap
的BitmapImage,我有一个Canvas(也是富有想象力的标题) canvas
。
How would I set the value of canvas
to the value of bitmap
? 如何将canvas
的值设置为bitmap
的值?
I've tried canvas.Background = bitmap;
我试过canvas.Background = bitmap;
, but that didn't work: image.Source = bitmap;
,但这不起作用: image.Source = bitmap;
works for images, but not Canvases: and 适用于图像,但不适用于画布:和
ImageSourceConverter imgs = new ImageSourceConverter(); canvas.SetValue(Image.SourceProperty, imgs.ConvertFromString(bitmap.ToString()));
didn't work either. 也没用。
All of these worked with images, however. 然而,所有这些都适用于图像。
Maybe something with bitmap.ToString()
would work? 也许bitmap.ToString()
东西可以工作?
Create an ImageBrush
and use that as the background: 创建一个ImageBrush
并将其用作背景:
ImageBrush ib = new ImageBrush();
ib.ImageSource = bitmap;
canvas.Background = ib;
只是:
canvas.Background = new ImageBrush(bitmap);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.