简体   繁体   English

将BitmapImage转换为System.Windows.Media.Brush

[英]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.

相关问题 将System.Windows.Media.Brush转换为System.Drawing.Brush - Convert System.Windows.Media.Brush to System.Drawing.Brush C#如何将system.windows.media.brush转换为system.drawing.brush - C# how to convert system.windows.media.brush to system.drawing.brush 将Color作为#XXXXXX等字符串转换为System.Windows.Media.Brush的最简单方法 - Simpliest way to convert a Color as a string like #XXXXXX to System.Windows.Media.Brush 将system.windows.media.brush转换为Hex颜色代码 - Converting system.windows.media.brush to Hex color code 'ColorAnimation' 动画对象不能用于为属性 'Background' 设置动画,因为它是不兼容的类型 'System.Windows.Media.Brush' - 'ColorAnimation' animation object cannot be used to animate property 'Background' because it is of incompatible type 'System.Windows.Media.Brush' 将System.Drawing.Bitmap转换为WPF的System.Windows.Media.BitmapImage - Convert System.Drawing.Bitmap to System.Windows.Media.BitmapImage for WPF 如何将System.Windows.Media.Imaging.BitmapImage转换为System.Drawing.Image? - How to Convert System.Windows.Media.Imaging.BitmapImage to System.Drawing.Image? 如何将'System.Windows.Media.Imaging.BitmapImage'转换为'System.Drawing.Image'? - How to convert 'System.Windows.Media.Imaging.BitmapImage' to 'System.Drawing.Image'? 将XNA Texture2D转换为System.Windows.Media.Imaging.BitmapImage - Convert XNA Texture2D to System.Windows.Media.Imaging.BitmapImage 如何从BitmapImage获取数组System.Windows.Media.Color? - How to get an array System.Windows.Media.Color from a BitmapImage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM