简体   繁体   English

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

[英]Convert System.Windows.Media.Brush to System.Drawing.Brush

How can I convert a System.Windows.Media.Brush to System.Drawing.Brush? 如何将System.Windows.Media.Brush转换为System.Drawing.Brush?

I'm trying to get the color of a system.windows.media.brush formatted to a System.Drawing.Color object. 我正在尝试将system.windows.media.brush的颜色格式化为System.Drawing.Color对象。

The below solution doesn't work because it requires a solidcolorbrush object, whereas the object i need converting from is a system.windows.media.brush object: 下面的解决方案不起作用,因为它需要solidcolorbrush对象,而我需要转换的对象是system.windows.media.brush对象:

public System.Drawing.Color GetColor( System.Windows.Media.SolidColorBrush oBrush )
{
   return System.Drawing.Color.FromArgb( oBrush.Color.A,
                                     oBrush.Color.R,
                                     oBrush.Color.G,
                                     oBrush.Color.B );
}

I believe you can just cast it as a SolidColorBrush to get the color. 我相信你可以把它作为SolidColorBrush投射来获得颜色。

Try something like: 尝试类似的东西:

MyColor = ((SolidColorBrush)MyMediaBrush).Color;
   System.Drawing.Color c1 = new System.Drawing.Color();
            c1 = System.Drawing.Color.FromName(Properties.Settings.Default.myColor);
            System.Windows.Media.Color c2 = new Color();
            c2 = Color.FromArgb(c1.A, c1.R, c1.G, c1.B);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#如何将system.windows.media.brush转换为system.drawing.brush - C# how to convert system.windows.media.brush to system.drawing.brush 将BitmapImage转换为System.Windows.Media.Brush - Convert BitmapImage to System.Windows.Media.Brush 将system.windows.media.brush转换为Hex颜色代码 - Converting system.windows.media.brush to Hex color code 将Color作为#XXXXXX等字符串转换为System.Windows.Media.Brush的最简单方法 - Simpliest way to convert a Color as a string like #XXXXXX to System.Windows.Media.Brush System.Drawing.Crush来自System.Drawing.Color - System.Drawing.Brush from System.Drawing.Color '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' WPF无法将system.drawing.bitmap隐式转换为media.brush - WPF cannot implicitly convert system.drawing.bitmap to media.brush 将System.Windows.Media.Pen转换为System.Drawing.Pen - Convert System.Windows.Media.Pen to System.Drawing.Pen 画刷 - Drawing to a brush 将System.Windows.Media.ImageSource转换为System.Drawing.Bitmap - Convert System.Windows.Media.ImageSource to System.Drawing.Bitmap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM