Pen 类

Summary: Defines an object used to draw lines, curves and figures.

Module: aspose.imaging

Full Name: aspose.imaging.Pen

Inheritance: TransparencySupporter

Constructors

Name描述
Pen(brush)使用指定的 Pen.brush 初始化 Pen 类的新实例。
Pen(brush, width)使用指定的 Pen.brushPen.width 初始化 Pen 类的新实例。
Pen(color)使用指定的颜色初始化 Pen 类的新实例。
Pen(color, width)使用指定的 Pen.colorPen.width 属性初始化 Pen 类的新实例。

Properties

NameTypeAccess描述
alignmentPenAlignmentr/w获取或设置此 Pen 的对齐方式。
brushBrushr/w获取或设置 Pen.brush,它决定此 Pen 的属性。
colorColorr/w获取或设置此 Pen 的颜色。
compound_arrayfloat[]r/w获取或设置指定复合笔的值数组。复合笔绘制由平行线段和间隔组成的复合线。
custom_end_capCustomLineCapr/w获取或设置在使用此 Pen 绘制的线条末端使用的自定义帽。
custom_start_capCustomLineCapr/w获取或设置在使用此 Pen 绘制的线条起始端使用的自定义帽。
dash_capDashCapr/w获取或设置在使用此 Pen 绘制的虚线末端的帽式样式。
dash_offsetfloatr/w获取或设置从线段起点到虚线模式起始位置的距离。
dash_patternfloat[]r/w获取或设置自定义虚线和空格的数组。
dash_styleDashStyler/w获取或设置使用此Pen绘制的虚线的样式。
end_capLineCapr/w获取或设置使用此Pen绘制的线段末端的端帽样式。
line_joinLineJoinr/w获取或设置使用此Pen绘制的两条相邻线段端点的连接样式。
miter_limitfloatr/w获取或设置斜接拐角处连接的厚度限制。
opacityfloatr/w获取或设置对象的不透明度。该值应在 0 到 1 之间。0 表示对象完全可见,1 表示对象完全不透明。
pen_typePenTyper获取使用此Pen绘制的线条样式。
start_capLineCapr/w获取或设置使用此Pen绘制的线段起始端的端帽样式。
transformMatrixr/w获取或设置此Pen的几何变换的副本。
widthfloatr/w获取或设置此Pen的宽度,单位为用于绘图的 Graphics 对象的单位。

Methods

Name描述
create_with_brush(brush)使用指定的 Pen.brush 初始化 Pen 类的新实例。
create_with_brush_width(brush, width)使用指定的 Pen.brushPen.width 初始化 Pen 类的新实例。
create_with_color(color)使用指定的颜色初始化 Pen 类的新实例。
create_with_color_width(color, width)使用指定的 Pen.colorPen.width 属性初始化 Pen 类的新实例。
multiply_transform(matrix)将此Pen的变换矩阵乘以指定的Matrix
multiply_transform(matrix, order)按照指定顺序,将此Pen的变换矩阵乘以指定的Matrix
reset_transform()将此Pen的几何变换矩阵重置为单位矩阵。
rotate_transform(angle)按指定角度旋转局部几何变换。此方法将在变换前添加旋转。
rotate_transform(angle, order)按指定顺序,以指定角度旋转局部几何变换。
scale_transform(sx, sy)按指定因子缩放局部几何变换。此方法将在变换前添加缩放矩阵。
scale_transform(sx, sy, order)按指定顺序,以指定因子缩放局部几何变换。
set_line_cap(start_cap, end_cap, dash_cap)设置决定此Pen绘制的线段结束端帽样式的值。
translate_transform(dx, dy)按指定尺寸平移局部几何变换。此方法将在变换前添加平移。
translate_transform(dx, dy, order)按指定顺序,以指定尺寸平移局部几何变换。

Constructor: Pen(brush)

 Pen(brush) 

使用指定的 Pen.brush 初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
brushBrush一个决定此Pen填充属性的Pen.brush

Constructor: Pen(brush, width)

 Pen(brush, width) 

使用指定的 Pen.brushPen.width 初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
brushBrush一个决定此Pen特性的Pen.brush
widthfloatPen的宽度。

Constructor: Pen(color)

 Pen(color) 

使用指定的颜色初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
colorColor一个指示此Pen颜色的Pen.color结构。

Constructor: Pen(color, width)

 Pen(color, width) 

使用指定的 Pen.colorPen.width 属性初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
colorColor一个指示此Pen颜色的Pen.color结构。
widthfloat指示此 Pen 宽度的值。

See also:

Example # 1: This example shows the creation and usage Pen objects. The example creates a …

Method: create_with_brush(brush) [static]

 create_with_brush(brush) 

使用指定的 Pen.brush 初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
brushBrush一个决定此Pen填充属性的Pen.brush

Returns

TypeDescription
Pen

Method: create_with_brush_width(brush, width) [static]

 create_with_brush_width(brush, width) 

使用指定的 Pen.brushPen.width 初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
brushBrush一个决定此Pen特性的Pen.brush
widthfloatPen的宽度。

Returns

TypeDescription
Pen

Method: create_with_color(color) [static]

 create_with_color(color) 

使用指定的颜色初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
colorColor一个指示此Pen颜色的Pen.color结构。

Returns

TypeDescription
Pen

Method: create_with_color_width(color, width) [static]

 create_with_color_width(color, width) 

使用指定的 Pen.colorPen.width 属性初始化 Pen 类的新实例。

Parameters:

参数TypeDescription
colorColor一个指示此Pen颜色的Pen.color结构。
widthfloat指示此 Pen 宽度的值。

Returns

TypeDescription
Pen

Method: multiply_transform(matrix)

 multiply_transform(matrix) 

将此Pen的变换矩阵乘以指定的Matrix

Parameters:

参数TypeDescription
matrixMatrix用于乘以变换矩阵的 Matrix 对象。

Method: multiply_transform(matrix, order)

 multiply_transform(matrix, order) 

按照指定顺序,将此Pen的变换矩阵乘以指定的Matrix

Parameters:

参数TypeDescription
matrixMatrix用于乘以变换矩阵的 Matrix
orderMatrixOrder执行乘法操作的顺序。

Method: rotate_transform(angle)

 rotate_transform(angle) 

按指定角度旋转局部几何变换。此方法将在变换前添加旋转。

Parameters:

参数TypeDescription
角度float旋转角度。

Method: rotate_transform(angle, order)

 rotate_transform(angle, order) 

按指定顺序,以指定角度旋转局部几何变换。

Parameters:

参数TypeDescription
角度float旋转角度。
orderMatrixOrder指定是追加还是预置旋转矩阵的 MatrixOrder

Method: scale_transform(sx, sy)

 scale_transform(sx, sy) 

按指定因子缩放局部几何变换。此方法将在变换前添加缩放矩阵。

Parameters:

参数TypeDescription
sxfloat在 x 轴方向上缩放变换的因子。
syfloat在 y 轴方向上缩放变换的因子。

Method: scale_transform(sx, sy, order)

 scale_transform(sx, sy, order) 

按指定顺序,以指定因子缩放局部几何变换。

Parameters:

参数TypeDescription
sxfloat在 x 轴方向上缩放变换的因子。
syfloat在 y 轴方向上缩放变换的因子。
orderMatrixOrder一个 MatrixOrder 用于指定是追加还是预先追加缩放矩阵。

Method: set_line_cap(start_cap, end_cap, dash_cap)

 set_line_cap(start_cap, end_cap, dash_cap) 

设置决定此Pen绘制的线段结束端帽样式的值。

Parameters:

参数TypeDescription
start_capLineCap表示使用此 [Pen] 绘制的线段起始处的帽子样式的 LineCap
end_capLineCap表示使用此 [Pen] 绘制的线段末端的帽子样式的 LineCap
dash_capDashCap表示使用此 [Pen] 绘制的虚线起始或结束处的帽子样式的 LineCap

Method: translate_transform(dx, dy)

 translate_transform(dx, dy) 

按指定尺寸平移局部几何变换。此方法将在变换前添加平移。

Parameters:

参数TypeDescription
dxfloatx 方向的平移值。
dyfloaty 方向的平移值。

Method: translate_transform(dx, dy, order)

 translate_transform(dx, dy, order) 

按指定顺序,以指定尺寸平移局部几何变换。

Parameters:

参数TypeDescription
dxfloatx 方向的平移值。
dyfloaty 方向的平移值。
orderMatrixOrder应用平移的顺序(预先追加或追加)。

Examples

This example shows the creation and usage Pen objects. The example creates a new Image and draw rectangles on the Image surface.


from aspose.imaging import Image, Graphics, Color, Pen, Rectangle, Point, Size
from aspose.imaging.brushes import HatchBrush
from aspose.imaging.imageoptions import BmpOptions
from aspose.imaging.sources import FileCreateSource

# 创建 BmpOptions 实例并设置其各种属性。
bmpOptions = BmpOptions()
bmpOptions.bits_per_pixel = 24
# 创建 FileCreateSource 的实例并将其分配为 BmpOptions 实例的 Source
# 第二个布尔参数决定要创建的文件是否为临时文件
bmpOptions.source = FileCreateSource(r"C:\temp\sample.bmp", False)
# 在指定路径创建 Image 实例。
with Image.create(bmpOptions, 500, 500) as image:
	# 创建 Graphics 实例并使用 Image 对象进行初始化。
	graphics = Graphics(image)
	# 使用白色清除 Graphics 表面。
	graphics.clear(Color.white)
	#创建颜色为红色、宽度为 5 的 Pen 实例。
	pen = Pen(Color.red, 5.0);
	# 创建 HatchBrush 实例并设置其属性。
	brush = HatchBrush()
	brush.background_color = Color.wheat;
	brush.foreground_color = Color.red;
	# 创建 Pen 实例。
	# 使用 HatchBrush 对象和宽度进行初始化
	brusedpen = Pen(brush, 5.0)
	# 通过指定 Pen 对象绘制矩形
	graphics.draw_rectangles(pen, [
		Rectangle(Point(210, 210), Size(100, 100)),
		Rectangle(Point(110, 110), Size(100, 100)),
		Rectangle(Point(310, 310), Size(100, 100)) ])

	# 通过指定 Pen 对象绘制矩形
	graphics.draw_rectangles(brusedpen, [
		Rectangle(Point(310, 110), Size(100, 100)),
		Rectangle(Point(110, 310), Size(100, 100)) ])

	# 保存所有更改。
	image.save()