vb.net 从颜色转换为画笔
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5183856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting from a color to a brush
提问by Connor Albright
How do I convert from system.drawing.color to system.drawing.brushes in vb.net?
如何在 vb.net 中从 system.drawing.color 转换为 system.drawing.brushes?
Meta question: What is/why the difference between a brush/color/pen?
元问题:画笔/颜色/笔之间的区别是什么/为什么?
回答by Pondidum
This should do it for you:
这应该为你做:
'just a solid brush:
Using br = New SolidBrush(Colors.Black)
e.Graphics.FillRectangle(br, New Rectangle(50, 50, 10, 10))
End Using
'A red -> orange gradient, at 45 degrees:
Using br = New LinearGradientBrush(new Rectangle(50, 50, 10, 10), Color.Red, Color.Orange, 25)
e.Graphics.FillRectangle(br, New Rectangle(50, 50, 10, 10))
End Using
回答by KeithS
A "Brush" is a style of fill drawing, incorporating both a Color and a Pattern. A Pen is similar to a Brush but defines a style of line drawing. To go from a Color to a Brush, you need to create a new Brush and give it the Color. The Brush class itself is abstract; its child classes specify various basic, customizable patterns of drawing. Pens are similar, but as lines are drawn as if they were filled rectangles, a Brush may be necessary to customize the "fill" of the line. The Pen object then has additional properties governing style that are specific to drawing a line. Take a look on MSDN: http://msdn.microsoft.com/en-us/library/d78x2d7s%28v=VS.71%29.aspx
“画笔”是一种填充绘图风格,包含颜色和图案。Pen 类似于 Brush,但定义了一种线条绘制风格。要将颜色转换为画笔,您需要创建一个新画笔并为其指定颜色。Brush 类本身是抽象的;它的子类指定了各种基本的、可定制的绘图模式。钢笔是类似的,但当线条被绘制成填充矩形时,可能需要画笔来自定义线条的“填充”。然后 Pen 对象具有控制特定于绘制线条的样式的附加属性。看看 MSDN:http: //msdn.microsoft.com/en-us/library/d78x2d7s%28v=VS.71%29.aspx
回答by Rob P.
They are entirely different things.
它们是完全不同的东西。
Here is an article entitled 'Pens, Brushes and Colors' http://msdn.microsoft.com/en-us/library/aa983677(v=vs.71).aspx
这是一篇题为“钢笔、画笔和颜色”的文章 http://msdn.microsoft.com/en-us/library/aa983677(v=vs.71).aspx
Pens
A pen is used to draw lines, curves, and to outline shapesBrushes
Brushes are objects that are used with a Graphics object to create solid shapes and to render text.
钢笔
钢笔用于绘制线条、曲线和勾勒形状画笔
画笔是与 Graphics 对象一起使用以创建实体形状和呈现文本的对象。
Both Pens and Brushes have a 'Color' that they are using...but you can't turn a Color into a brush. It's like a car. You can't turn 'Red' into a car, but a car can be red.
钢笔和画笔都有他们正在使用的“颜色”……但是你不能把颜色变成画笔。这就像一辆汽车。你不能把“红色”变成汽车,但汽车可以是红色的。
回答by Rob
Dim myColor As Color
Dim myBrush As Brush
Dim myPen As Pen
'From Color to brush/pen
myBrush = New SolidBrush(myColor)
myPen = New Pen(myColor)
'From Brush to color/pen
myPen = New Pen(myBrush)
myColor = New Pen(myBrush).Color
'From Pen to color/brush
myColor = myPen.Color
myBrush = New SolidBrush(myPen.Color)
回答by Javed Akram
pen is used to draw outlines of figure.
brush is used to fill inside area of closed figure.
Color is the look of color.
钢笔用于绘制图形的轮廓。
画笔用于填充封闭图形的内部区域。
颜色是颜色的外观。
Brush and Pen may have same color but their role are diffrent
画笔和笔的颜色可能相同,但作用不同