本文整理汇总了C#中System.Windows.Media.Brush.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Brush.GetType方法的具体用法?C# Brush.GetType怎么用?C# Brush.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Brush
的用法示例。
在下文中一共展示了Brush.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckErrorAtBgBrush
/// <summary>背景色から問題を確認</summary>
/// <param name="b">Background(Brush)を想定</param>
/// <returns>結果:true = 問題なし、false = 問題あり</returns>
public static bool CheckErrorAtBgBrush(Brush b)
{
SolidColorBrush scb = new SolidColorBrush(Colors.Red);
if (b.GetType() == scb.GetType())
{
if (((SolidColorBrush)b).Color == scb.Color) { return false; }
else { return true; }
}
else { return true; }
}
示例2: AreBrushesEqual
public static bool AreBrushesEqual(Brush first, Brush second)
{
// If the default comparison is true, that's good enough.
if (object.Equals(first, second))
{
return true;
}
if (first.GetType().Name == "SolidColorBrush")
{
// Do a field by field comparison if they're not the same reference
SolidColorBrush firstSolidColorBrush = first as SolidColorBrush;
if (firstSolidColorBrush != null)
{
SolidColorBrush secondSolidColorBrush = second as SolidColorBrush;
if (secondSolidColorBrush != null)
{
return object.Equals(firstSolidColorBrush.Color, secondSolidColorBrush.Color);
}
}
}
else
{
// Do a field by field comparison if they're not the same reference
LinearGradientBrush firstLinearColorBrush = first as LinearGradientBrush;
if (firstLinearColorBrush != null)
{
LinearGradientBrush secondLinearColorBrush = second as LinearGradientBrush;
if (secondLinearColorBrush != null)
{
Boolean stop1 = object.Equals(firstLinearColorBrush.GradientStops[0].Color, secondLinearColorBrush.GradientStops[0].Color);
Boolean stop2 = object.Equals(firstLinearColorBrush.GradientStops[1].Color, secondLinearColorBrush.GradientStops[1].Color);
return object.Equals(stop1, stop2);
}
}
}
return false;
}
示例3: ExtractColor
public static Color ExtractColor(Brush brush)
{
if (brush is SolidColorBrush)
{
return ((SolidColorBrush)brush).Color;
}
else if (brush is GradientBrush)
{
GradientBrush brushCast = (GradientBrush)brush;
Color average = AverageColors(brushCast.GradientStops.Select(o => o.Color));
if (brushCast.Opacity.IsNearZero())
{
return Color.FromArgb(0, average.R, average.G, average.B);
}
else if (brushCast.Opacity.IsNearValue(1))
{
return average;
}
else
{
double opacity = average.A / 255d;
opacity *= brushCast.Opacity;
return Color.FromArgb((opacity * 255d).ToByte_Round(), average.R, average.G, average.B);
}
}
else
{
throw new ArgumentException("Unsupported brush type: " + brush.GetType().ToString());
}
}
示例4: SetForeground
public static void SetForeground(this HtmlStyleDictionary style, Brush foreground, IHtmlValueConverter converter)
{
if (foreground == null)
{
style.ClearValue("color");
}
else if (foreground is SolidColorBrush)
{
style.SetValue("color", converter.ToColorString((SolidColorBrush)foreground));
}
else
{
throw new Granular.Exception("A \"{0}\" foreground brush is not supported", foreground.GetType());
}
}
示例5: SwapColorsWithoutCloning
private static void SwapColorsWithoutCloning(Brush brush, ColorCallback colorCallback)
{
if (brush != null)
{
SolidColorBrush brush2 = brush as SolidColorBrush;
if (brush2 != null)
{
brush2.Color = colorCallback(brush2.Color);
}
else
{
GradientBrush brush3 = brush as GradientBrush;
if (brush3 == null)
{
DrawingBrush brush4 = brush as DrawingBrush;
if (brush4 != null)
{
SwapColorsWithoutCloning(brush4.Drawing, colorCallback);
}
else
{
ImageBrush brush5 = brush as ImageBrush;
if (brush5 != null)
{
brush5.ImageSource = SwapColorsWithoutCloningIfPossible(brush5.ImageSource, colorCallback);
}
else if (!(brush is VisualBrush))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "UnexpectedBrushType", new object[] { brush.GetType().Name }));
}
}
}
else
{
foreach (GradientStop stop in brush3.GradientStops)
{
stop.Color = colorCallback(stop.Color);
}
}
}
}
}
示例6: IsEqualTo
/// <summary>
/// Verifies if the given brush is the same as the otherBrush.
/// </summary>
/// <param name="brush">Brush</param>
/// <param name="otherBrush">Brush</param>
/// <returns>true if yes, otherwise false</returns>
public static bool IsEqualTo(this Brush brush, Brush otherBrush)
{
if (brush.GetType() != otherBrush.GetType())
return false;
if (ReferenceEquals(brush, otherBrush))
return true;
// Are both instances of SolidColorBrush
var solidBrushA = brush as SolidColorBrush;
var solidBrushB = otherBrush as SolidColorBrush;
if ((solidBrushA != null) && (solidBrushB != null))
{
return (solidBrushA.Color == solidBrushB.Color)
&& solidBrushA.Opacity.IsCloseTo(solidBrushB.Opacity);
}
// Are both instances of LinearGradientBrush
var linGradBrushA = brush as LinearGradientBrush;
var linGradBrushB = otherBrush as LinearGradientBrush;
if ((linGradBrushA != null) && (linGradBrushB != null))
{
var result = (linGradBrushA.ColorInterpolationMode == linGradBrushB.ColorInterpolationMode)
&& (linGradBrushA.EndPoint == linGradBrushB.EndPoint)
&& (linGradBrushA.MappingMode == linGradBrushB.MappingMode)
&& linGradBrushA.Opacity.IsCloseTo(linGradBrushB.Opacity)
&& (linGradBrushA.StartPoint == linGradBrushB.StartPoint)
&& (linGradBrushA.SpreadMethod == linGradBrushB.SpreadMethod)
&& (linGradBrushA.GradientStops.Count == linGradBrushB.GradientStops.Count);
if (!result)
return false;
for (var i = 0; i < linGradBrushA.GradientStops.Count; i++)
{
result = (linGradBrushA.GradientStops[i].Color == linGradBrushB.GradientStops[i].Color)
&& linGradBrushA.GradientStops[i].Offset.IsCloseTo(linGradBrushB.GradientStops[i].Offset);
if (!result)
break;
}
return result;
}
// Are both instances of RadialGradientBrush
var radGradBrushA = brush as RadialGradientBrush;
var radGradBrushB = otherBrush as RadialGradientBrush;
if ((radGradBrushA != null) && (radGradBrushB != null))
{
var result = (radGradBrushA.ColorInterpolationMode == radGradBrushB.ColorInterpolationMode)
&& (radGradBrushA.GradientOrigin == radGradBrushB.GradientOrigin)
&& (radGradBrushA.MappingMode == radGradBrushB.MappingMode)
&& radGradBrushA.Opacity.IsCloseTo(radGradBrushB.Opacity)
&& radGradBrushA.RadiusX.IsCloseTo(radGradBrushB.RadiusX)
&& radGradBrushA.RadiusY.IsCloseTo(radGradBrushB.RadiusY)
&& (radGradBrushA.SpreadMethod == radGradBrushB.SpreadMethod)
&& (radGradBrushA.GradientStops.Count == radGradBrushB.GradientStops.Count);
if (!result)
return false;
for (var i = 0; i < radGradBrushA.GradientStops.Count; i++)
{
result = (radGradBrushA.GradientStops[i].Color == radGradBrushB.GradientStops[i].Color)
&& radGradBrushA.GradientStops[i].Offset.IsCloseTo(radGradBrushB.GradientStops[i].Offset);
if (!result)
break;
}
return result;
}
// Are both instances of ImageBrush
var imgBrushA = brush as ImageBrush;
var imgBrushB = otherBrush as ImageBrush;
if ((imgBrushA != null) && (imgBrushB != null))
{
var result = (imgBrushA.AlignmentX == imgBrushB.AlignmentX)
&& (imgBrushA.AlignmentY == imgBrushB.AlignmentY)
&& imgBrushA.Opacity.IsCloseTo(imgBrushB.Opacity)
&& (imgBrushA.Stretch == imgBrushB.Stretch)
&& (imgBrushA.TileMode == imgBrushB.TileMode)
&& (imgBrushA.Viewbox == imgBrushB.Viewbox)
&& (imgBrushA.ViewboxUnits == imgBrushB.ViewboxUnits)
&& (imgBrushA.Viewport == imgBrushB.Viewport)
&& (imgBrushA.ViewportUnits == imgBrushB.ViewportUnits)
&& (imgBrushA.ImageSource == imgBrushB.ImageSource);
return result;
}
//.........这里部分代码省略.........
示例7: GetDarkerColor
/// <summary>
/// Get darker color for Radar series
/// </summary>
/// <param name="seriesColor"></param>
/// <returns></returns>
private static Brush GetDarkerColor(Brush seriesColor)
{
if (seriesColor != null && seriesColor.GetType().Equals(typeof(SolidColorBrush)))
{
Double intensity = Graphics.GetBrushIntensity(seriesColor);
Color color = Graphics.GetDarkerColor(Color.FromArgb((Byte)255, (seriesColor as SolidColorBrush).Color.R, (seriesColor as SolidColorBrush).Color.G, (seriesColor as SolidColorBrush).Color.B), intensity);
Brush newBrush = Graphics.CreateSolidColorBrush(color);
return newBrush;
}
else
return seriesColor;
}
示例8: Get3DBrushLighting
/// <summary>
/// Get 3dBrush with or without lighting for bubble
/// </summary>
internal static Brush Get3DBrushLighting(Brush solidColorBrush, Boolean lightingEnabled)
{
if (solidColorBrush.GetType().Equals(typeof(SolidColorBrush)))
{
Color color = (solidColorBrush as SolidColorBrush).Color;
RadialGradientBrush rgb = new RadialGradientBrush()
{
Center = new Point(0.3, 0.3),
RadiusX = 0.93,
RadiusY = 1,
GradientOrigin = new Point(0.2, 0.2)
};
if (color == Colors.Black)
{
if(lightingEnabled)
rgb.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0 });
rgb.GradientStops.Add(new GradientStop() { Color = Colors.Gray, Offset = 0.1 });
rgb.GradientStops.Add(new GradientStop() { Color = Colors.Black, Offset = 1 });
}
else
{
Color darkerColor = Graphics.GetDarkerColor(color, 0.2);
if (lightingEnabled)
rgb.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0 });
rgb.GradientStops.Add(new GradientStop() { Color = color, Offset = 0.1 });
rgb.GradientStops.Add(new GradientStop() { Color = darkerColor, Offset = 1 });
}
return rgb;
}
else
return solidColorBrush;
}
示例9: GetBevelTopBrush
/// <summary>
/// Creates and returns bevel top brush
/// </summary>
/// <param name="brush">Brush</param>
/// <param name="angle">Angle</param>
/// <returns>Brush</returns>
internal static Brush GetBevelTopBrush(Brush brush, Double angle)
{
if (brush != null)
{
if (typeof(SolidColorBrush).Equals(brush.GetType()))
{
SolidColorBrush solidBrush = brush as SolidColorBrush;
Double r, g, b;
List<Color> colors = new List<Color>();
List<Double> stops = new List<Double>();
r = ((double)solidBrush.Color.R / (double)255) * 0.9999;
g = ((double)solidBrush.Color.G / (double)255) * 0.9999;
b = ((double)solidBrush.Color.B / (double)255) * 0.9999;
colors.Add(Graphics.GetLighterColor(solidBrush.Color, 0.99));
stops.Add(0);
colors.Add(Graphics.GetLighterColor(solidBrush.Color, 1 - r, 1 - g, 1 - b));
stops.Add(0.2);
colors.Add(Graphics.GetLighterColor(solidBrush.Color, 1 - r, 1 - g, 1 - b));
stops.Add(0.6);
colors.Add(Graphics.GetLighterColor(solidBrush.Color, 0.99));
stops.Add(1);
return Graphics.CreateLinearGradientBrush(angle, new Point(0, 0.5), new Point(1, 0.5), colors, stops);
}
else
{
return brush;
}
}
else
return null;
}
示例10: GetBrushIntensity
/// <summary>
/// Creates and returns a brush intensity
/// </summary>
/// <param name="brush">Brush</param>
/// <returns>Double</returns>
public static Double GetBrushIntensity(Brush brush)
{
Color color = new Color();
Double intensity = 0;
if (brush == null) return 1;
if (brush.GetType().Name == "SolidColorBrush")
{
color = (brush as SolidColorBrush).Color;
intensity = (Double)(color.R + color.G + color.B) / (3 * 255);
}
else if (brush.GetType().Name == "LinearGradientBrush" || brush.GetType().Name == "RadialGradientBrush")
{
foreach (GradientStop grad in (brush as GradientBrush).GradientStops)
{
color = grad.Color;
intensity += (Double)(color.R + color.G + color.B) / (3 * 255);
}
intensity /= (brush as GradientBrush).GradientStops.Count;
}
else
{
intensity = 1;
}
return intensity;
}
示例11: GetFrontFaceBrush
/// <summary>
/// Creates and returns a Back face brush
/// </summary>
/// <param name="brush">Brush</param>
/// <returns>Brush</returns>
internal static Brush GetFrontFaceBrush(Brush brush)
{
if (brush != null)
{
if (typeof(SolidColorBrush).Equals(brush.GetType()))
{
SolidColorBrush solidBrush = brush as SolidColorBrush;
if (_3dLightingFrontBrushs.ContainsKey(solidBrush.Color))
return _3dLightingFrontBrushs[solidBrush.Color];
else
{
List<Color> colors = new List<Color>();
List<Double> stops = new List<Double>();
colors.Add(Graphics.GetDarkerColor(solidBrush.Color, 0.65));
stops.Add(0);
colors.Add(Graphics.GetLighterColor(solidBrush.Color, 0.55));
stops.Add(1);
brush = Graphics.CreateLinearGradientBrush(-90, new Point(0, 0.5), new Point(1, 0.5), colors, stops);
_3dLightingFrontBrushs.Add(solidBrush.Color, brush);
return brush;
}
}
else
{
return brush;
}
}
else
return null;
}
示例12: GetFrontFaceBrush
/// <summary>
/// Creates and returns a Back face brush
/// </summary>
/// <param name="brush">Brush</param>
/// <returns>Brush</returns>
internal static Brush GetFrontFaceBrush(Brush brush)
{
if (brush != null)
{
if (typeof(SolidColorBrush).Equals(brush.GetType()))
{
SolidColorBrush solidBrush = brush as SolidColorBrush;
if (_3dLightingFrontBrushs.ContainsKey(solidBrush.Color))
{
#if WPF
if (System.Threading.Thread.CurrentThread.IsBackground)
{
brush = GetFrontFaceGradientBrush(solidBrush);
if (_3dLightingFrontBrushs.ContainsKey(solidBrush.Color))
_3dLightingFrontBrushs[solidBrush.Color] = brush;
else
_3dLightingFrontBrushs.Add(solidBrush.Color, brush);
return brush;
}
#endif
return _3dLightingFrontBrushs[solidBrush.Color];
}
else
{
brush = GetFrontFaceGradientBrush(solidBrush);
_3dLightingFrontBrushs.Add(solidBrush.Color, brush);
return brush;
}
}
else
{
return brush;
}
}
else
return null;
}
示例13: GetRightFaceBrush
/// <summary>
/// Creates and returns a right face brush
/// </summary>
/// <param name="brush">Brush</param>
/// <returns>Brush</returns>
internal static Brush GetRightFaceBrush(Brush brush)
{
if (brush != null)
{
if (typeof(SolidColorBrush).Equals(brush.GetType()))
{
SolidColorBrush solidBrush = brush as SolidColorBrush;
if (_3dLightingRightBrushs.ContainsKey(solidBrush.Color))
{
#if WPF
if (System.Threading.Thread.CurrentThread.IsBackground)
{
brush = GetRightFaceGradientBrush(solidBrush);
if (_3dLightingRightBrushs.ContainsKey(solidBrush.Color))
_3dLightingRightBrushs[solidBrush.Color] = brush;
else
_3dLightingRightBrushs.Add(solidBrush.Color, brush);
return brush;
}
#endif
return _3dLightingRightBrushs[solidBrush.Color];
}
else
{
brush = GetRightFaceGradientBrush(solidBrush);
_3dLightingRightBrushs.Add(solidBrush.Color, brush);
return brush;
}
}
else if (brush is GradientBrush)
{
GradientBrush gradBrush = brush as GradientBrush;
List<Color> colors = new List<Color>();
List<Double> stops = new List<Double>();
foreach (GradientStop gradStop in gradBrush.GradientStops)
{
colors.Add(Graphics.GetDarkerColor(gradStop.Color, 0.75));
stops.Add(gradStop.Offset);
}
if (brush is LinearGradientBrush)
return Graphics.CreateLinearGradientBrush(0, new Point(0, 1), new Point(1, 0), colors, stops);
else
return Graphics.CreateRadialGradientBrush(colors, stops);
}
else
{
return brush;
}
}
else
return null;
}
示例14: GetCurvedBevelBrush
/// <summary>
/// Returns curved bevel brush
/// </summary>
/// <param name="brush">Brush</param>
/// <param name="angle">Angle as Double</param>
/// <param name="shade">Shade as DoubleCollection</param>
/// <param name="offset">Offset as DoubleCollection</param>
/// <returns>Brush</returns>
internal static Brush GetCurvedBevelBrush(Brush brush, Double angle, DoubleCollection shade, DoubleCollection offset)
{
if (typeof(SolidColorBrush).Equals(brush.GetType()))
{
SolidColorBrush solidBrush = brush as SolidColorBrush;
List<Color> colors = new List<Color>();
List<Double> stops = new List<double>();
for (Int32 i = 0; i < shade.Count; i++)
{
Color newShade = (shade[i] < 0 ? Graphics.GetDarkerColor(solidBrush.Color, Math.Abs(shade[i])) : Graphics.GetLighterColor(solidBrush.Color, Math.Abs(shade[i])));
colors.Add(newShade);
}
for (Int32 i = 0; i < offset.Count; i++)
{
stops.Add(offset[i]);
}
return Graphics.CreateLinearGradientBrush(angle, new Point(0, 0.5), new Point(1, 0.5), colors, stops);
}
else
{
return brush;
}
}
示例15: GetTopFaceBrush
/// <summary>
/// Creates and returns a top face brush
/// </summary>
/// <param name="brush">Brush</param>
/// <returns>Brush</returns>
internal static Brush GetTopFaceBrush(Brush brush)
{
if (brush != null)
{
if (typeof(SolidColorBrush).Equals(brush.GetType()))
{
SolidColorBrush solidBrush = brush as SolidColorBrush;
if(_3dLightingTopBrushs.ContainsKey(solidBrush.Color))
return _3dLightingTopBrushs[solidBrush.Color];
else
{
List<Color> colors = new List<Color>();
List<Double> stops = new List<Double>();
colors.Add(Graphics.GetDarkerColor(solidBrush.Color, 0.85));
stops.Add(0);
colors.Add(Graphics.GetLighterColor(solidBrush.Color, 0.35));
stops.Add(1);
brush = Graphics.CreateLinearGradientBrush(-45, new Point(0, 0.5), new Point(1, 0.5), colors, stops);
_3dLightingTopBrushs.Add(solidBrush.Color, brush);
return brush;
}
}
else if (brush is GradientBrush)
{
GradientBrush gradBrush = brush as GradientBrush;
List<Color> colors = new List<Color>();
List<Double> stops = new List<Double>();
foreach (GradientStop gradStop in gradBrush.GradientStops)
{
colors.Add(Graphics.GetLighterColor(gradStop.Color, 0.85));
stops.Add(gradStop.Offset);
}
if (brush is LinearGradientBrush)
return Graphics.CreateLinearGradientBrush(-45, new Point(-0.5, 1.5), new Point(0.5, 0), colors, stops);
else
return Graphics.CreateRadialGradientBrush(colors, stops);
}
else
{
return brush;
}
}
else
return null;
}