Class Brush

Class Brush

Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.2.0)

基础画刷类。

[JsonObject(MemberSerialization.OptIn)]
public abstract class Brush : DisposableObject, IDisposable

继承

objectDisposableObjectBrush

派生

HatchBrush, SolidBrush, TransformBrush

实现

IDisposable

继承的成员

DisposableObject.Dispose(), DisposableObject.ReleaseManagedResources(), DisposableObject.ReleaseUnmanagedResources(), DisposableObject.VerifyNotDisposed(), DisposableObject.Disposed, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

构造函数

Brush()

protected Brush()

属性

不透明度

获取或设置画刷的不透明度。值应在0到1之间。值为0表示画刷完全可见,值为1表示画刷完全不透明。

public float Opacity { get; set; }

属性值

float

示例

此示例使用 Graphics 类在图像表面创建基本形状。为了演示操作,示例创建一个新的 PNG 格式图像,并使用 Graphics 类提供的 Draw 方法在图像表面绘制基本形状。```csharp [C#]

                                                                                                                                                                                                                                                            //创建 FileStream 的实例
                                                                                                                                                                                                                                                            using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                //创建 PngOptions 的实例并设置其各种属性
                                                                                                                                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                                                                                                                                //为 PngOptions 设置源
                                                                                                                                                                                                                                                                pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

                                                                                                                                                                                                                                                                //创建图像的实例 
                                                                                                                                                                                                                                                                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                    //创建并初始化 Graphics 类的实例
                                                                                                                                                                                                                                                                    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);

                                                                                                                                                                                                                                                                    //清除 Graphics 表面
                                                                                                                                                                                                                                                                    graphics.Clear(Aspose.Imaging.Color.Wheat);

                                                                                                                                                                                                                                                                    //通过指定具有黑色的 Pen 对象、围绕弧的矩形、起始角度和扫掠角度绘制弧
                                                                                                                                                                                                                                                                    graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);

                                                                                                                                                                                                                                                                    //通过指定具有蓝色的 Pen 对象和坐标点绘制贝塞尔曲线
                                                                                                                                                                                                                                                                    graphics.DrawBezier(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Point(250, 100), new Aspose.Imaging.Point(300, 30), new Aspose.Imaging.Point(450, 100), new Aspose.Imaging.Point(235, 25));

                                                                                                                                                                                                                                                                    //通过指定具有绿色的 Pen 对象和点数组绘制曲线
                                                                                                                                                                                                                                                                    graphics.DrawCurve(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new[] { new Aspose.Imaging.Point(100, 200), new Aspose.Imaging.Point(100, 350), new Aspose.Imaging.Point(200, 450) });

                                                                                                                                                                                                                                                                    //使用 Pen 对象和围绕的矩形绘制椭圆
                                                                                                                                                                                                                                                                    graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));

                                                                                                                                                                                                                                                                    //绘制一条直线 
                                                                                                                                                                                                                                                                    graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));

                                                                                                                                                                                                                                                                    //绘制一个扇形
                                                                                                                                                                                                                                                                    graphics.DrawPie(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Silver, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(200, 20), new Aspose.Imaging.Size(200, 200)), 0, 45);

                                                                                                                                                                                                                                                                    //通过指定具有红色的 Pen 对象和点数组绘制多边形
                                                                                                                                                                                                                                                                    graphics.DrawPolygon(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 2), new[] { new Aspose.Imaging.Point(20, 100), new Aspose.Imaging.Point(20, 200), new Aspose.Imaging.Point(220, 20) });

                                                                                                                                                                                                                                                                    //绘制矩形
                                                                                                                                                                                                                                                                    graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(250, 250), new Aspose.Imaging.Size(100, 100)));

                                                                                                                                                                                                                                                                    //创建 SolidBrush 对象并设置其各种属性
                                                                                                                                                                                                                                                                    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
                                                                                                                                                                                                                                                                    brush.Color = Color.Purple;
                                                                                                                                                                                                                                                                    brush.Opacity = 100;

                                                                                                                                                                                                                                                                    //使用 SolidBrush 对象和字体在特定点绘制字符串
                                                                                                                                                                                                                                                                    graphics.DrawString("此图像是由 Aspose.Imaging API 创建的", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));

                                                                                                                                                                                                                                                                    //保存所有更改。
                                                                                                                                                                                                                                                                    image.Save();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

## 方法

### <a id="Aspose_Imaging_Brush_DeepClone"></a> DeepClone\(\)

创建当前 Aspose.Imaging.Brush 的新深度克隆。

```csharp
public virtual Brush DeepClone()

返回

Brush

一个新的 Aspose.Imaging.Brush,它是此 Aspose.Imaging.Brush 实例的深度克隆。

Equals(object)

检查对象是否相等。

public override bool Equals(object obj)

参数

obj object

另一个对象。

返回

bool

相等比较结果。

Equals(Brush)

检查对象是否相等。

protected bool Equals(Brush other)

参数

other Brush

另一个对象。

返回

bool

相等比较结果。

GetHashCode()

获取当前对象的哈希代码。

public override int GetHashCode()

返回

int

哈希代码。

 中文