PolygonShape 类

Summary: Represents a polygon shape.

Module: aspose.imaging.shapes

Full Name: aspose.imaging.shapes.PolygonShape

Inheritance: IOrderedShape, Shape

Constructors

Name描述
PolygonShape()初始化 PolygonShape 类的新实例。
PolygonShape(points)初始化 PolygonShape 类的新实例。
PolygonShape(points, is_closed)初始化 PolygonShape 类的新实例。

Properties

NameTypeAccess描述
boundsRectangleFr获取对象的边界。
centerPointFr获取形状的中心。
end_pointPointFr获取结束形状点。
has_segmentsboolr获取一个值,指示形状是否具有段。
is_closedboolr/w获取或设置指示形状是否闭合的值。
pointsPointF[]r/w获取或设置曲线点。
segmentsShapeSegment[]r获取形状的段。
start_pointPointFr获取起始形状点。

Methods

Name描述
get_bounds(matrix)获取对象的边界。
get_bounds(matrix, pen)获取对象的边界。
reverse()反转此形状的点顺序。
transform(transform)对形状应用指定的变换。

Constructor: PolygonShape()

 PolygonShape() 

初始化 PolygonShape 类的新实例。

Constructor: PolygonShape(points)

 PolygonShape(points) 

初始化 PolygonShape 类的新实例。

Parameters:

参数TypeDescription
pointsPointF[]点数组。

Constructor: PolygonShape(points, is_closed)

 PolygonShape(points, is_closed) 

初始化 PolygonShape 类的新实例。

Parameters:

参数TypeDescription
pointsPointF[]点数组。
is_closedbool如果设置为 true,则多边形闭合。

Method: get_bounds(matrix)

 get_bounds(matrix) 

获取对象的边界。

Parameters:

参数TypeDescription
matrixMatrix在计算边界之前要应用的矩阵。

Returns

TypeDescription
RectangleF估计的对象边界。

Method: get_bounds(matrix, pen)

 get_bounds(matrix, pen) 

获取对象的边界。

Parameters:

参数TypeDescription
matrixMatrix在计算边界之前要应用的矩阵。
penPen用于对象的笔。这可能会影响对象边界的大小。

Returns

TypeDescription
RectangleF估计的对象边界。

Method: transform(transform)

 transform(transform) 

对形状应用指定的变换。

Parameters:

参数TypeDescription
transformMatrix要应用的变换。

Examples

This example creates a new Image and draws a variety of shapes using figures and GraphicsPath on the Image surface


from aspose.imaging import Image, Graphics, Color, GraphicsPath, Figure, RectangleF, Rectangle, Size
from aspose.imaging import Point, PointF, Pen
from aspose.imaging.imageoptions import BmpOptions
from aspose.imaging.sources import FileCreateSource
from aspose.imaging.shapes import EllipseShape, PieShape, ArcShape, PolygonShape, RectangleShape
from os.path import join as path_join

#创建 BmpOptions 的实例并设置其各种属性            
with BmpOptions() as bmpOptions:
	bmpOptions.bits_per_pixel = 24
	#创建 FileCreateSource 的实例并将其分配为 BmpOptions 实例的 Source
	#第二个布尔参数决定要创建的文件是否为临时文件
	bmpOptions.source = FileCreateSource(r"c:\temp\output.bmp", False)
	#创建 Image 实例
	with Image.create(bmpOptions, 500, 500) as image:
		# 创建并初始化 Graphics 类的实例
		graphics = Graphics(image)
		# 清除 Graphics 表面
		graphics.clear(Color.wheat)
		# 创建 GraphicsPath 类的实例
		graphicspath = GraphicsPath()
		#创建 Figure 类的实例
		figure1 = Figure()
		# 向 Figure 对象添加形状
		figure1.add_shape(EllipseShape(RectangleF(50, 50, 300, 300)))
		figure1.add_shape(PieShape(Rectangle(Point(110, 110), Size(200, 200)), 0, 90))
		# 创建 Figure 类的实例
		figure2 = Figure()
		# 向 Figure 对象添加形状
		figure2.add_shape(ArcShape(RectangleF(10, 10, 300, 300), 0, 45))
		figure2.add_shape(
			PolygonShape([PointF(150, 10), PointF(150, 200), PointF(250, 300), PointF(350, 400)], True))
		figure2.add_shape(RectangleShape(RectangleF(Point(250, 250), Size(200, 200))))
		# 将 Figure 对象添加到 GraphicsPath
		graphicspath.add_figures([figure1, figure2])
		# 使用颜色为 Black 的 Pen 对象绘制路径
		graphics.draw_path(Pen(Color.black, 2.0), graphicspath)
		# 保存所有更改。
		image.save()