Class HatchBrush
Class HatchBrush
Namespace: Aspose.Imaging.Brushes
Assembly: Aspose.Imaging.dll (25.2.0)
定义了一个具有斜线样式、前景色和背景色的矩形画刷。此类不能被继承。
[JsonObject(MemberSerialization.OptIn)]
public sealed class HatchBrush : Brush, IDisposable
继承
object ← DisposableObject ← Brush ← HatchBrush
实现
继承成员
Brush.DeepClone(), Brush.Equals(object), Brush.GetHashCode(), Brush.Opacity, DisposableObject.Dispose(), DisposableObject.Disposed, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
示例
此示例展示了 Pen 对象的创建和使用。该示例创建了一个新的图像并在图像表面上绘制矩形。```csharp [C#]
//创建 BmpOptions 的实例并设置其各种属性
Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
bmpOptions.BitsPerPixel = 24;
//创建 FileCreateSource 的实例并将其分配为 BmpOptions 实例的源
//第二个布尔参数决定要创建的文件是否为临时文件
bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\sample.bmp", false);
//在指定路径创建图像实例
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
{
//创建 Graphics 的实例并用图像对象初始化
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
//用白色清除 Graphics 表面
graphics.Clear(Aspose.Imaging.Color.White);
//创建一个颜色为红色、宽度为 5 的 Pen 实例
Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 5f);
//创建 HatchBrush 的实例并设置其属性
Aspose.Imaging.Brushes.HatchBrush brush = new Aspose.Imaging.Brushes.HatchBrush();
brush.BackgroundColor = Aspose.Imaging.Color.Wheat;
brush.ForegroundColor = Aspose.Imaging.Color.Red;
//创建 Pen 的实例
//用 HatchBrush 对象和宽度初始化
Aspose.Imaging.Pen brusedpen = new Pen(brush, 5);
//通过指定 Pen 对象绘制矩形
graphics.DrawRectangles(pen, new[]
{
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(210, 210), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 110), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 310), new Aspose.Imaging.Size(100, 100))
});
//通过指定 Pen 对象绘制矩形
graphics.DrawRectangles(brusedpen, new[]
{
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 110), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 310), new Aspose.Imaging.Size(100, 100))
});
//保存所有更改。
image.Save();
}
## 构造函数
### <a id="Aspose_Imaging_Brushes_HatchBrush__ctor"></a> HatchBrush\(\)
```csharp
public HatchBrush()
属性
BackgroundColor
获取或设置斜线之间空间的颜色。
public Color BackgroundColor { get; set; }
属性值
示例
此示例展示了 Pen 对象的创建和使用。该示例创建了一个新的图像并在图像表面上绘制矩形。```csharp [C#]
//创建 BmpOptions 的实例并设置其各种属性
Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
bmpOptions.BitsPerPixel = 24;
//创建 FileCreateSource 的实例并将其分配为 BmpOptions 实例的源
//第二个布尔参数决定要创建的文件是否为临时文件
bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\sample.bmp", false);
//在指定路径创建图像实例
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
{
//创建 Graphics 的实例并用图像对象初始化
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
//用白色清除 Graphics 表面
graphics.Clear(Aspose.Imaging.Color.White);
//创建一个颜色为红色、宽度为 5 的 Pen 实例
Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 5f);
//创建 HatchBrush 的实例并设置其属性
Aspose.Imaging.Brushes.HatchBrush brush = new Aspose.Imaging.Brushes.HatchBrush();
brush.BackgroundColor = Aspose.Imaging.Color.Wheat;
brush.ForegroundColor = Aspose.Imaging.Color.Red;
//创建 Pen 的实例
//用 HatchBrush 对象和宽度初始化
Aspose.Imaging.Pen brusedpen = new Pen(brush, 5);
//通过指定 Pen 对象绘制矩形
graphics.DrawRectangles(pen, new[]
{
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(210, 210), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 110), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 310), new Aspose.Imaging.Size(100, 100))
});
//通过指定 Pen 对象绘制矩形
graphics.DrawRectangles(brusedpen, new[]
{
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 110), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 310), new Aspose.Imaging.Size(100, 100))
});
//保存所有更改。
image.Save();
}
### <a id="Aspose_Imaging_Brushes_HatchBrush_ForegroundColor"></a> ForegroundColor
获取或设置斜线的颜色。
```csharp
public Color ForegroundColor { get; set; }
属性值
示例
此示例展示了 Pen 对象的创建和使用。该示例创建了一个新的图像并在图像表面上绘制矩形。```csharp [C#]
//创建 BmpOptions 的实例并设置其各种属性
Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
bmpOptions.BitsPerPixel = 24;
//创建 FileCreateSource 的实例并将其分配为 BmpOptions 实例的源
//第二个布尔参数决定要创建的文件是否为临时文件
bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\sample.bmp", false);
//在指定路径创建图像实例
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
{
//创建 Graphics 的实例并用图像对象初始化
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
//用白色清除 Graphics 表面
graphics.Clear(Aspose.Imaging.Color.White);
//创建一个颜色为红色、宽度为 5 的 Pen 实例
Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 5f);
//创建 HatchBrush 的实例并设置其属性
Aspose.Imaging.Brushes.HatchBrush brush = new Aspose.Imaging.Brushes.HatchBrush();
brush.BackgroundColor = Aspose.Imaging.Color.Wheat;
brush.ForegroundColor = Aspose.Imaging.Color.Red;
//创建 Pen 的实例
//用 HatchBrush 对象和宽度初始化
Aspose.Imaging.Pen brusedpen = new Pen(brush, 5);
//通过指定 Pen 对象绘制矩形
graphics.DrawRectangles(pen, new[]
{
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(210, 210), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 110), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 310), new Aspose.Imaging.Size(100, 100))
});
//通过指定 Pen 对象绘制矩形
graphics.DrawRectangles(brusedpen, new[]
{
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 110), new Aspose.Imaging.Size(100, 100)),
new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 310), new Aspose.Imaging.Size(100, 100))
});
//保存所有更改。
image.Save();
}
### <a id="Aspose_Imaging_Brushes_HatchBrush_HatchStyle"></a> HatchStyle
获取或设置此画刷的斜线样式。
```csharp
public HatchStyle HatchStyle { get; set; }