Figure

Inheritance: java.lang.Object, com.aspose.imaging.ObjectWithBounds

public class Figure extends ObjectWithBounds

该图形。形状的容器。

构造函数

构造函数描述
Figure()初始化一个新的 Figure 实例。

方法

方法描述
getShapes()获取图形的形状。
getBounds()获取或设置对象的边界。
isClosed()获取指示此图形是否闭合的值。
setClosed(boolean value)设置指示此图形是否闭合的值。
getSegments()获取整个图形的段。
addShape(Shape shape)向图形添加形状。
addShapes(Shape[] shapes)向图形添加一系列形状。
removeShape(Shape shape)从图形中移除形状。
removeShapes(Shape[] shapes)从图形中移除一系列形状。
reverse()反转此图形的形状顺序和形状点的顺序。
getBounds(Matrix matrix)获取对象的边界。
getBounds(Matrix matrix, Pen pen)获取对象的边界。
transform(Matrix transform)对形状应用指定的变换。
equals(Object obj)确定指定的对象是否等于当前对象。
hashCode()用作默认的哈希函数。

Example: This examples make use of GraphicsPath and Graphics class to create and manipulate Figures on an Image surface.

这些示例使用 GraphicsPath 和 Graphics 类在 Image 表面上创建和操作图形。示例创建一个新的 Image(类型为 Tiff),并借助 GraphicsPath 类绘制路径。最后调用 Graphics 类提供的 DrawPath 方法在表面上渲染路径。

// 创建 FileStream 的实例
com.aspose.imaging.system.io.FileStream stream = new com.aspose.imaging.system.io.FileStream("C:\\temp\\output.tif", com.aspose.imaging.system.io.FileMode.Create);
try {
    // 创建 TiffOptions 的实例并设置其各种属性
    com.aspose.imaging.imageoptions.TiffOptions tiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);

    // 为 ImageOptions 实例设置源
    tiffOptions.setSource(new com.aspose.imaging.sources.StreamSource(stream));

    // 创建 Image 的实例
    com.aspose.imaging.Image image = com.aspose.imaging.Image.create(tiffOptions, 500, 500);
    try {
        // 创建并初始化 Graphics 类的实例
        com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);

        // 清除 Graphics 表面
        graphics.clear(com.aspose.imaging.Color.getWheat());

        // 创建 GraphicsPath 类的实例
        com.aspose.imaging.GraphicsPath graphicspath = new com.aspose.imaging.GraphicsPath();

        // 创建 Figure 类的实例
        com.aspose.imaging.Figure figure = new com.aspose.imaging.Figure();

        // 向 Figure 对象添加形状
        figure.addShape(new com.aspose.imaging.shapes.RectangleShape(new com.aspose.imaging.RectangleF(10, 10, 300, 300)));
        figure.addShape(new com.aspose.imaging.shapes.EllipseShape(new com.aspose.imaging.RectangleF(50, 50, 300, 300)));
        figure.addShape(
                new com.aspose.imaging.shapes.PieShape(new com.aspose.imaging.RectangleF(
                        new com.aspose.imaging.PointF(250, 250),
                        new com.aspose.imaging.SizeF(200, 200)),
                        0, 45));

        // 将 Figure 对象添加到 GraphicsPath
        graphicspath.addFigure(figure);

        // 使用颜色为 Black 的 Pen 对象绘制路径
        graphics.drawPath(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlack(), 2), graphicspath);

        // 保存所有更改。
        image.save();
    } finally {
        image.dispose();
    }
} finally {
    stream.dispose();
}

Figure()

public Figure()

初始化一个新的 Figure 实例。此构造函数用于 JSON 反序列化。

getShapes()

public Shape[] getShapes()

获取图形的形状。

Returns: com.aspose.imaging.Shape[] - 图形的形状。

getBounds()

public RectangleF getBounds()

获取或设置对象的边界。

Returns: RectangleF - The object’s bounds.

isClosed()

public boolean isClosed()

获取一个值,指示此图形是否闭合。闭合图形仅在首尾图形的形状是连续形状的情况下才会产生差异。在这种情况下,第一形状的起点将通过一条直线与最后形状的终点相连。

Returns: boolean - 如果此图形闭合则为 True;否则为 false

setClosed(boolean value)

public void setClosed(boolean value)

设置一个值,指示此图形是否闭合。闭合图形仅在首尾图形的形状是连续形状的情况下才会产生差异。在这种情况下,第一形状的起点将通过一条直线与最后形状的终点相连。

Parameters:

参数类型描述
valuebooleanTrue 如果此图形闭合;否则为 false

getSegments()

public ShapeSegment[] getSegments()

获取整个图形的段。

Returns: com.aspose.imaging.ShapeSegment[] - 图形的段。

addShape(Shape shape)

public void addShape(Shape shape)

向图形添加形状。

Parameters:

参数类型描述
shapeShape要添加的形状。

Example: This examples make use of GraphicsPath and Graphics class to create and manipulate Figures on an Image surface. 这些示例使用 GraphicsPath 和 Graphics 类在 Image 表面上创建和操作图形。示例创建一个新的 Image(类型为 Tiff),并借助 GraphicsPath 类绘制路径。最后调用 Graphics 类提供的 DrawPath 方法在表面上渲染路径。

// 创建 FileStream 的实例
com.aspose.imaging.system.io.FileStream stream = new com.aspose.imaging.system.io.FileStream("C:\\temp\\output.tif", com.aspose.imaging.system.io.FileMode.Create);
try {
    // 创建 TiffOptions 的实例并设置其各种属性
    com.aspose.imaging.imageoptions.TiffOptions tiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);

    // 为 ImageOptions 实例设置源
    tiffOptions.setSource(new com.aspose.imaging.sources.StreamSource(stream));

    // 创建 Image 的实例
    com.aspose.imaging.Image image = com.aspose.imaging.Image.create(tiffOptions, 500, 500);
    try {
        // 创建并初始化 Graphics 类的实例
        com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);

        // 清除 Graphics 表面
        graphics.clear(com.aspose.imaging.Color.getWheat());

        // 创建 GraphicsPath 类的实例
        com.aspose.imaging.GraphicsPath graphicspath = new com.aspose.imaging.GraphicsPath();

        // 创建 Figure 类的实例
        com.aspose.imaging.Figure figure = new com.aspose.imaging.Figure();

        // 向 Figure 对象添加形状
        figure.addShape(new com.aspose.imaging.shapes.RectangleShape(new com.aspose.imaging.RectangleF(10, 10, 300, 300)));
        figure.addShape(new com.aspose.imaging.shapes.EllipseShape(new com.aspose.imaging.RectangleF(50, 50, 300, 300)));
        figure.addShape(
                new com.aspose.imaging.shapes.PieShape(new com.aspose.imaging.RectangleF(
                        new com.aspose.imaging.PointF(250, 250),
                        new com.aspose.imaging.SizeF(200, 200)),
                        0, 45));

        // 将 Figure 对象添加到 GraphicsPath
        graphicspath.addFigure(figure);

        // 使用颜色为 Black 的 Pen 对象绘制路径
        graphics.drawPath(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlack(), 2), graphicspath);

        // 保存所有更改。
        image.save();
    } finally {
        image.dispose();
    }
} finally {
    stream.dispose();
}

addShapes(Shape[] shapes)

public void addShapes(Shape[] shapes)

向图形添加一系列形状。

Parameters:

参数类型描述
shapesShape[]要添加的形状。

removeShape(Shape shape)

public void removeShape(Shape shape)

从图形中移除形状。

Parameters:

参数类型描述
shapeShape要移除的形状。

removeShapes(Shape[] shapes)

public void removeShapes(Shape[] shapes)

从图形中移除一系列形状。

Parameters:

参数类型描述
shapesShape[]要移除的形状范围。

reverse()

public void reverse()

反转此图形的形状顺序和形状点的顺序。

getBounds(Matrix matrix)

public RectangleF getBounds(Matrix matrix)

获取对象的边界。

Parameters:

参数类型描述
matrixMatrix在计算边界之前要应用的矩阵。

Returns: RectangleF - The estimated object’s bounds.

getBounds(Matrix matrix, Pen pen)

public RectangleF getBounds(Matrix matrix, Pen pen)

获取对象的边界。

Parameters:

参数类型描述
matrixMatrix在计算边界之前要应用的矩阵。
penPen用于对象的笔。它可能影响对象的边界尺寸。

Returns: RectangleF - The estimated object’s bounds.

transform(Matrix transform)

public void transform(Matrix transform)

对形状应用指定的变换。

Parameters:

参数类型描述
transformMatrix要应用的转换。

equals(Object obj)

public boolean equals(Object obj)

确定指定的对象是否等于当前对象。

Parameters:

参数类型描述
objjava.lang.Object被比较的对象。

Returns: boolean - equals 的结果

hashCode()

public int hashCode()

用作默认的哈希函数。

Returns: int - 当前对象的哈希码。