Class SolidBrush
Namespace: Aspose.Imaging.Brushes
Assembly: Aspose.Imaging.dll (25.2.0)
Bút vẽ đặc được thiết kế để vẽ liên tục với màu sắc cụ thể. Lớp này không thể kế thừa.
public sealed class SolidBrush : Brush, IDisposable
Kế thừa
object ← DisposableObject ← Brush ← SolidBrush
Triển khai
Các thành viên được kế thừa
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()
Ví dụ
Ví dụ này sử dụng lớp Graphics để tạo hình dạng nguyên thủy trên bề mặt Hình ảnh. Để minh họa hoạt động, ví dụ tạo một Hình ảnh mới ở định dạng PNG và vẽ các hình dạng nguyên thủy trên bề mặt Hình ảnh bằng cách sử dụng các phương thức Draw được lớp Graphics cung cấp```csharp [C#]
//Tạo một thể hiện của FileStream
using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
{
//Tạo một thể hiện của PngOptions và thiết lập các thuộc tính khác nhau
Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
//Thiết lập Nguồn cho PngOptions
pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);
//Tạo một thể hiện của Hình ảnh
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
{
//Tạo và khởi tạo một thể hiện của lớp Graphics
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
//Xóa bề mặt Graphics
graphics.Clear(Aspose.Imaging.Color.Wheat);
//Vẽ một cung bằng cách chỉ định đối tượng Pen có màu Đen,
//một Hình chữ nhật bao quanh cung, Góc bắt đầu và Góc quét
graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);
//Vẽ một Bezier bằng cách chỉ định đối tượng Pen có màu Xanh và các Điểm tọa độ.
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));
//Vẽ một Đường cong bằng cách chỉ định đối tượng Pen có màu Xanh lá và một mảng các Điểm
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) });
//Vẽ một Elip bằng cách sử dụng đối tượng Pen và một Hình chữ nhật bao quanh
graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));
//Vẽ một Đường thẳng
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));
//Vẽ một đoạn Bánh
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);
//Vẽ một Đa giác bằng cách chỉ định đối tượng Pen có màu Đỏ và một mảng các Điểm
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) });
//Vẽ một Hình chữ nhật
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)));
//Tạo một đối tượng SolidBrush và thiết lập các thuộc tính khác nhau
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
brush.Color = Color.Purple;
brush.Opacity = 100;
//Vẽ một Chuỗi bằng cách sử dụng đối tượng SolidBrush và Font, tại Điểm cụ thể
graphics.DrawString("Hình ảnh này được tạo bởi API Aspose.Imaging", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));
// lưu tất cả các thay đổi.
image.Save();
}
}
## Các hàm khởi tạo
### <a id="Aspose_Imaging_Brushes_SolidBrush__ctor"></a> SolidBrush\(\)
Khởi tạo một thể hiện mới của lớp Aspose.Imaging.Brushes.SolidBrush.
```csharp
public SolidBrush()
Ví dụ
Ví dụ này sử dụng lớp Graphics để tạo hình dạng nguyên thủy trên bề mặt Hình ảnh. Để minh họa hoạt động, ví dụ tạo một Hình ảnh mới ở định dạng PNG và vẽ các hình dạng nguyên thủy trên bề mặt Hình ảnh bằng cách sử dụng các phương thức Draw được lớp Graphics cung cấp```csharp [C#]
//Tạo một thể hiện của FileStream
using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
{
//Tạo một thể hiện của PngOptions và thiết lập các thuộc tính khác nhau
Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
//Thiết lập Nguồn cho PngOptions
pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);
//Tạo một thể hiện của Hình ảnh
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
{
//Tạo và khởi tạo một thể hiện của lớp Graphics
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
//Xóa bề mặt Graphics
graphics.Clear(Aspose.Imaging.Color.Wheat);
//Vẽ một cung bằng cách chỉ định đối tượng Pen có màu Đen,
//một Hình chữ nhật bao quanh cung, Góc bắt đầu và Góc quét
graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);
//Vẽ một Bezier bằng cách chỉ định đối tượng Pen có màu Xanh và các Điểm tọa độ.
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));
//Vẽ một Đường cong bằng cách chỉ định đối tượng Pen có màu Xanh lá và một mảng các Điểm
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) });
//Vẽ một Elip bằng cách sử dụng đối tượng Pen và một Hình chữ nhật bao quanh
graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));
//Vẽ một Đường thẳng
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));
//Vẽ một đoạn Bánh
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);
//Vẽ một Đa giác bằng cách chỉ định đối tượng Pen có màu Đỏ và một mảng các Điểm
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) });
//Vẽ một Hình chữ nhật
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)));
//Tạo một đối tượng SolidBrush và thiết lập các thuộc tính khác nhau
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
brush.Color = Color.Purple;
brush.Opacity = 100;
//Vẽ một Chuỗi bằng cách sử dụng đối tượng SolidBrush và Font, tại Điểm cụ thể
graphics.DrawString("Hình ảnh này được tạo bởi API Aspose.Imaging", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));
// lưu tất cả các thay đổi.
image.Save();
}
}
### <a id="Aspose_Imaging_Brushes_SolidBrush__ctor_Aspose_Imaging_Color_"></a> SolidBrush\(Color\)
Khởi tạo một thể hiện mới của lớp Aspose.Imaging.Brushes.SolidBrush.
```csharp
public SolidBrush(Color color)
Tham số
color
Color
Màu sắc của bút vẽ đặc.
Thuộc tính
Color
Lấy hoặc thiết lập màu của bút vẽ.
[JsonProperty]
public Color Color { get; set; }
Giá trị thuộc tính
Ví dụ
Ví dụ này sử dụng lớp Graphics để tạo hình dạng nguyên thủy trên bề mặt Hình ảnh. Để minh họa hoạt động, ví dụ tạo một Hình ảnh mới ở định dạng PNG và vẽ các hình dạng nguyên thủy trên bề mặt Hình ảnh bằng cách sử dụng các phương thức Draw được lớp Graphics cung cấp```csharp [C#]
//Tạo một thể hiện của FileStream
using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
{
//Tạo một thể hiện của PngOptions và thiết lập các thuộc tính khác nhau
Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
//Thiết lập Nguồn cho PngOptions
pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);
//Tạo một thể hiện của Hình ảnh
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
{
//Tạo và khởi tạo một thể hiện của lớp Graphics
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
//Xóa bề mặt Graphics
graphics.Clear(Aspose.Imaging.Color.Wheat);
//Vẽ một cung bằng cách chỉ định đối tượng Pen có màu Đen,
//một Hình chữ nhật bao quanh cung, Góc bắt đầu và Góc quét
graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);
//Vẽ một Bezier bằng cách chỉ định đối tượng Pen có màu Xanh và các Điểm tọa độ.
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));
//Vẽ một Đường cong bằng cách chỉ định đối tượng Pen có màu Xanh lá và một mảng các Điểm
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) });
//Vẽ một Elip bằng cách sử dụng đối tượng Pen và một Hình chữ nhật bao quanh
graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));
//Vẽ một Đường thẳng
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));
//Vẽ một đoạn Bánh
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);
//Vẽ một Đa giác bằng cách chỉ định đối tượng Pen có màu Đỏ và một mảng các Điểm
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) });
//Vẽ một Hình chữ nhật
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)));
//Tạo một đối tượng SolidBrush và thiết lập các thuộc tính khác nhau
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
brush.Color = Color.Purple;
brush.Opacity = 100;
//Vẽ một Chuỗi bằng cách sử dụng đối tượng SolidBrush và Font, tại Điểm cụ thể
graphics.DrawString("Hình ảnh này được tạo bởi API Aspose.Imaging", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));
// lưu tất cả các thay đổi.
image.Save();
}
}