MetafileRecorderGraphics2D

Inheritance: java.lang.Object

public abstract class MetafileRecorderGraphics2D

元文件记录器图形

构造函数

构造函数描述
MetafileRecorderGraphics2D()

方法

方法描述
getClip()获取或设置限制此 Graphics 绘图区域的 Region
setClip(Region value)获取或设置限制此 Graphics 绘图区域的 Region
getClipBounds()获取剪裁边界。
getBackgroundColor()获取背景颜色。
setBackgroundColor(Color value)设置背景颜色。
clear()清除 graphics 对象的状态
drawArc(Pen pen, Rectangle rect, float startAngle, float arcAngle)绘制由 Rectangle 结构指定的椭圆的一部分弧线。
drawCubicBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)绘制三次贝塞尔曲线。
drawPolyCubicBezier(Pen pen, Point[] points)绘制多段三次贝塞尔曲线。
drawEllipse(Pen pen, Rectangle rect)绘制椭圆。
fillEllipse(Brush brush, Rectangle rect)填充椭圆。
drawImage(RasterImage image, Point location)在指定位置绘制指定的 Image,使用其原始物理尺寸。
drawImage(byte[] imageBytes, Rectangle destRect, int srcUnit)绘制图像。
drawImage(InputStream stream, Rectangle destRect, int srcUnit)绘制图像。
drawImage(RasterImage image, Rectangle destRect, Rectangle srcRect, int srcUnit)在指定位置并使用指定尺寸绘制指定 Image 的指定部分。
drawLine(Pen pen, int x1, int y1, int x2, int y2)绘制直线。
drawLine(Pen pen, Point pt1, Point pt2)绘制直线。
drawPolyline(Pen pen, Point[] points)绘制折线。
drawPath(Pen pen, GraphicsPath path)绘制路径。
fillPath(Pen pen, Brush brush, GraphicsPath path)填充路径。
drawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)绘制饼形。
fillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)填充饼图。
drawPolygon(Pen pen, Point[] points)绘制多边形。
fillPolygon(Brush brush, Point[] points)填充多边形。
fillPolygon(Brush brush, Point[] points, int fillMode)填充多边形。
drawRectangle(Pen pen, int x, int y, int width, int height)绘制矩形。
drawRectangle(Pen pen, Rectangle rectangle)绘制矩形。
fillRectangle(Brush brush, Rectangle rectangle)填充矩形。
drawString(String string, Font font, Color color, int x, int y)绘制字符串。
drawString(String string, Font font, Color color, int x, int y, float angle)绘制字符串。
excludeClip(Rectangle rect)更新此 Graphics 的剪辑区域,以排除由 Rectangle 结构指定的区域。
excludeClip(Region region)更新此 Graphics 的剪辑区域,以排除由 Region 指定的区域。
intersectClip(RectangleF rect)更新此 Graphics 的剪辑区域,使其为当前剪辑区域与指定的 Rectangle 结构的交集。
intersectClip(Region region)更新此 Graphics 的剪辑区域,使其为当前剪辑区域与指定的 Region 的交集。
resetClip()重置剪辑。
multiplyTransform(Matrix matrix)将此 Graphics 的世界变换与指定的矩阵相乘。
multiplyTransform(Matrix matrix, int order)按指定顺序将此 Graphics 的世界变换与指定的矩阵相乘。
translateTransform(float x, float y)通过在此 Graphics 的变换矩阵前置指定的平移来更改坐标系的原点。
translateTransform(float x, float y, int order)按指定顺序将指定的平移应用于此 Graphics 的变换矩阵,以更改坐标系的原点。
rotateTransform(float angle)将指定的旋转应用于此 Graphics 的变换矩阵。
rotateTransform(float angle, PointF center, int order)按指定顺序将指定的旋转应用于此 Graphics 的变换矩阵。
scaleTransform(float sx, float sy)通过在对象的变换矩阵前置指定的缩放操作,将其应用于此 Graphics 的变换矩阵。
scaleTransform(float sx, float sy, int order)按指定顺序将指定的缩放操作应用于此 Graphics 的变换矩阵。
getTransform()获取世界变换。
setTransform(Matrix transform)设置变换。

Example: This example shows how to create a EMF image and draw some geometric shapes on it using EmfRecorderGraphics2D.

String dir = "c:\\temp\\";

// 图像的像素尺寸
int deviceWidth = 600;
int deviceHeight = 400;

// 图像的毫米尺寸
int deviceWidthMm = (int) (deviceWidth / 100f);
int deviceHeightMm = (int) (deviceHeight / 100f);

com.aspose.imaging.Rectangle frame = new com.aspose.imaging.Rectangle(0, 0, deviceWidth, deviceHeight);

// 创建 EMF 图像。
com.aspose.imaging.fileformats.emf.graphics.EmfRecorderGraphics2D graphics =
        new com.aspose.imaging.fileformats.emf.graphics.EmfRecorderGraphics2D(
                frame,
                new com.aspose.imaging.Size(deviceWidth, deviceHeight),
                new com.aspose.imaging.Size(deviceWidthMm, deviceHeightMm));

// 使用 1 像素宽的黑色笔在图像边框上绘制一个黑色矩形。
graphics.drawRectangle(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlack(), 1), 0, 0, deviceWidth, deviceHeight);

// 使用白烟色填充矩形。
graphics.fillRectangle(
        new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhiteSmoke()),
        new com.aspose.imaging.Rectangle(10, 10, 580, 380));

// 使用 1 像素宽的深绿色笔绘制两条对角线。
graphics.drawLine(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getDarkGreen(), 1), 0, 0, deviceWidth, deviceHeight);
graphics.drawLine(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getDarkGreen(), 1), 0, deviceHeight, deviceWidth, 0);

// 使用 2 像素宽的蓝色笔在矩形 {0, 0, 200, 200} 内绘制弧线。
graphics.drawArc(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlue(), 2), new com.aspose.imaging.Rectangle(0, 0, 200, 200), 90, 270);

// 填充弧线
graphics.fillPie(
        new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getLightSkyBlue()),
        new com.aspose.imaging.Rectangle(0, 0, 150, 150), 90, 270);

// 使用 2 像素宽的红色笔绘制三次贝塞尔曲线。
graphics.drawCubicBezier(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 2),
        new com.aspose.imaging.Point(0, 0),
        new com.aspose.imaging.Point(200, 133),
        new com.aspose.imaging.Point(400, 166),
        new com.aspose.imaging.Point(600, 400));

// 在指定位置绘制指定尺寸的光栅图像。
// 图像已缩放以适应所需的矩形。
com.aspose.imaging.RasterImage imageToDraw = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
    graphics.drawImage(imageToDraw,
            new com.aspose.imaging.Rectangle(400, 200, 100, 50),
            new com.aspose.imaging.Rectangle(0, 0, deviceWidth, deviceHeight),
            com.aspose.imaging.GraphicsUnit.Pixel);
} finally {
    imageToDraw.dispose();
}

// 绘制文本字符串
graphics.drawString("Hello World!",
        new com.aspose.imaging.Font("Arial", 48, com.aspose.imaging.FontStyle.Regular),
        com.aspose.imaging.Color.getDarkRed(), 200, 300);

// 创建用于填充的路径
com.aspose.imaging.Figure figureToFill = new com.aspose.imaging.Figure();
figureToFill.setClosed(true);

com.aspose.imaging.GraphicsPath pathToFill = new com.aspose.imaging.GraphicsPath();
pathToFill.addFigure(figureToFill);

figureToFill.addShapes(new com.aspose.imaging.Shape[]
        {
                new com.aspose.imaging.shapes.ArcShape(new com.aspose.imaging.RectangleF(400, 0, 200, 100), 45, 300),
                new com.aspose.imaging.shapes.BezierShape(
                        new com.aspose.imaging.PointF[]
                                {
                                        new com.aspose.imaging.PointF(300, 200),
                                        new com.aspose.imaging.PointF(400, 200),
                                        new com.aspose.imaging.PointF(500, 100),
                                        new com.aspose.imaging.PointF(600, 200),
                                }),
                new com.aspose.imaging.shapes.PolygonShape(
                        new com.aspose.imaging.PointF[]
                                {
                                        new com.aspose.imaging.PointF(300, 100),
                                }),
                new com.aspose.imaging.shapes.RectangleShape(new com.aspose.imaging.RectangleF(0, 100, 200, 200)),
        });

// 使用黄色画刷填充路径,并使用绿色笔绘制轮廓
graphics.fillPath(
        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getGreen(), 2),
        new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getYellow()), pathToFill);

// 创建用于绘制的路径
com.aspose.imaging.GraphicsPath pathToDraw = new com.aspose.imaging.GraphicsPath();
com.aspose.imaging.Figure figureToDraw = new com.aspose.imaging.Figure();
pathToDraw.addFigure(figureToDraw);

figureToDraw.addShapes(new com.aspose.imaging.Shape[]
        {
                new com.aspose.imaging.shapes.ArcShape(new com.aspose.imaging.RectangleF(200, 200, 200, 200), 0, 360),
        });

// 使用 5 像素宽的橙色笔绘制路径。
graphics.drawPath(new com.aspose.imaging.Pen(com.aspose.imaging.Color.getOrange(), 5), pathToDraw);

// 为了栅格化 SVG,我们需要指定栅格化选项。
com.aspose.imaging.imageoptions.SvgRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.SvgRasterizationOptions();
com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
saveOptions.setVectorRasterizationOptions(rasterizationOptions);

// 获取包含所有绘图命令的最终 WMF 图像
com.aspose.imaging.fileformats.emf.EmfImage emfImage = graphics.endRecording();
try {
    emfImage.save(dir + "test.output.emf");
} finally {
    emfImage.dispose();
}

MetafileRecorderGraphics2D()

public MetafileRecorderGraphics2D()

getClip()

public Region getClip()

获取或设置限制此 Graphics 绘图区域的 Region

Returns: Region - The clip region.

setClip(Region value)

public void setClip(Region value)

获取或设置限制此 Graphics 绘图区域的 Region

Parameters:

参数类型描述
valueRegion剪辑区域。

getClipBounds()

public RectangleF getClipBounds()

获取剪裁边界。

Returns: RectangleF - The clip bounds.

getBackgroundColor()

public Color getBackgroundColor()

获取背景颜色。

Returns: Color - The color of the background.

setBackgroundColor(Color value)

public void setBackgroundColor(Color value)

设置背景颜色。

Parameters:

参数类型描述
valueColor背景颜色。

clear()

public void clear()

清除 graphics 对象的状态

drawArc(Pen pen, Rectangle rect, float startAngle, float arcAngle)

public void drawArc(Pen pen, Rectangle rect, float startAngle, float arcAngle)

绘制由 Rectangle 结构指定的椭圆的一部分弧线。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
rectRectangle椭圆的边界。
startAnglefloat从 x 轴顺时针测量到弧起始点的角度(度)。
arcAnglefloat角度(以度为单位),从 startAngle 参数顺时针测量到弧的结束点。

drawCubicBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)

public void drawCubicBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)

绘制三次贝塞尔曲线。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
pt1Point曲线的起始点。
pt2Point曲线的第一个控制点。
pt3Point曲线的第二个控制点。
pt4Point曲线的结束点。

drawPolyCubicBezier(Pen pen, Point[] points)

public void drawPolyCubicBezier(Pen pen, Point[] points)

绘制多段三次贝塞尔曲线。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
pointsPoint[]这些点。

drawEllipse(Pen pen, Rectangle rect)

public void drawEllipse(Pen pen, Rectangle rect)

绘制椭圆。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
rectRectangle椭圆的边界。

fillEllipse(Brush brush, Rectangle rect)

public void fillEllipse(Brush brush, Rectangle rect)

填充椭圆。

Parameters:

参数类型描述
brushBrush决定填充特性的画刷。
rectRectangle椭圆的边界。

drawImage(RasterImage image, Point location)

public void drawImage(RasterImage image, Point location)

在指定位置绘制指定的 Image,使用其原始物理尺寸。

Parameters:

参数类型描述
imageRasterImage要绘制的图像。
locationPoint已绘制图像左上角的位置。

drawImage(byte[] imageBytes, Rectangle destRect, int srcUnit)

public final void drawImage(byte[] imageBytes, Rectangle destRect, int srcUnit)

绘制图像。

Parameters:

参数类型描述
imageBytesbyte[]图像字节。
destRectRectangle目标矩形。
srcUnitint源单位。

drawImage(InputStream stream, Rectangle destRect, int srcUnit)

public final void drawImage(InputStream stream, Rectangle destRect, int srcUnit)

绘制图像。

Parameters:

参数类型描述
java.io.InputStream流。
destRectRectangle目标矩形。
srcUnitint源单位。

drawImage(RasterImage image, Rectangle destRect, Rectangle srcRect, int srcUnit)

public void drawImage(RasterImage image, Rectangle destRect, Rectangle srcRect, int srcUnit)

在指定位置并使用指定尺寸绘制指定 Image 的指定部分。

Parameters:

参数类型描述
imageRasterImage要绘制的图像。
destRectRectangle指定已绘制图像位置和大小的矩形结构。图像会按比例缩放以适应该矩形。
srcRectRectangle指定要绘制的图像对象部分的矩形结构。
srcUnitintsrcRect 参数使用的度量单位。

drawLine(Pen pen, int x1, int y1, int x2, int y2)

public void drawLine(Pen pen, int x1, int y1, int x2, int y2)

绘制直线。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
x1int第一个点的 x 坐标。
y1int第一个点的 y 坐标。
x2int第二个点的 x 坐标。
y2int第二个点的 y 坐标。

drawLine(Pen pen, Point pt1, Point pt2)

public void drawLine(Pen pen, Point pt1, Point pt2)

绘制直线。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
pt1Point第一个点。
pt2Point第二个点。

drawPolyline(Pen pen, Point[] points)

public void drawPolyline(Pen pen, Point[] points)

绘制折线。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
pointsPoint[]这些点。

drawPath(Pen pen, GraphicsPath path)

public void drawPath(Pen pen, GraphicsPath path)

绘制路径。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
pathGraphicsPath要绘制的路径。

fillPath(Pen pen, Brush brush, GraphicsPath path)

public void fillPath(Pen pen, Brush brush, GraphicsPath path)

填充路径。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
brushBrush决定填充特性的画刷。
pathGraphicsPath要填充的路径。

drawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)

public void drawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)

绘制饼形。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
rectRectangle椭圆的边界。
startAnglefloat从 x 轴顺时针测量到弧起始点的角度(度)。
sweepAnglefloat角度(以度为单位),从 startAngle 参数顺时针测量到弧的结束点。

fillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)

public void fillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)

填充饼图。

Parameters:

参数类型描述
brushBrush决定填充特性的画刷。
rectRectangle椭圆的边界。
startAnglefloat从 x 轴顺时针测量到弧起始点的角度(度)。
sweepAnglefloat角度(以度为单位),从 startAngle 参数顺时针测量到弧的结束点。

drawPolygon(Pen pen, Point[] points)

public void drawPolygon(Pen pen, Point[] points)

绘制多边形。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
pointsPoint[]这些点。

fillPolygon(Brush brush, Point[] points)

public void fillPolygon(Brush brush, Point[] points)

填充多边形。

Parameters:

参数类型描述
brushBrush决定填充特性的画刷。
pointsPoint[]这些点。

fillPolygon(Brush brush, Point[] points, int fillMode)

public void fillPolygon(Brush brush, Point[] points, int fillMode)

填充多边形。

Parameters:

参数类型描述
brushBrush决定填充特性的画刷。
pointsPoint[]这些点。
fillModeint填充模式。

drawRectangle(Pen pen, int x, int y, int width, int height)

public void drawRectangle(Pen pen, int x, int y, int width, int height)

绘制矩形。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
xint要绘制的矩形左上角的 x 坐标。
yint要绘制的矩形左上角的 y 坐标。
宽度int要绘制的矩形的宽度。
高度int要绘制的矩形的高度。

drawRectangle(Pen pen, Rectangle rectangle)

public void drawRectangle(Pen pen, Rectangle rectangle)

绘制矩形。

Parameters:

参数类型描述
penPen确定图形颜色、宽度和样式的笔。
rectangleRectangle要绘制的矩形。

fillRectangle(Brush brush, Rectangle rectangle)

public void fillRectangle(Brush brush, Rectangle rectangle)

填充矩形。

Parameters:

参数类型描述
brushBrush决定填充特性的画刷。
rectangleRectangle要填充的矩形。

drawString(String string, Font font, Color color, int x, int y)

public void drawString(String string, Font font, Color color, int x, int y)

绘制字符串。

Parameters:

参数类型描述
字符串java.lang.String该字符串。
fontFont定义字符串文本格式的字体。
colorColor文本颜色。
xint已绘制文本左上角的 x 坐标。
yint已绘制文本左上角的 y 坐标。

Example: This example shows how to load a EMF image from a file and draw a text string over it.

String dir = "c:\\temp\\";

com.aspose.imaging.fileformats.emf.EmfImage emfImage = (com.aspose.imaging.fileformats.emf.EmfImage) com.aspose.imaging.Image.load(dir + "test.emf");
try {
    com.aspose.imaging.fileformats.emf.graphics.EmfRecorderGraphics2D graphics =
            com.aspose.imaging.fileformats.emf.graphics.EmfRecorderGraphics2D.fromEmfImage(emfImage);

    // 首先,获取图像尺寸
    int width = emfImage.getWidth();
    int height = emfImage.getHeight();

    // 其次,计算一个变换,以将文本字符串沿图像的主对角线放置 -
    // 从左上角到右下角。
    float emFontSize = 96f;
    float d = (float) java.lang.Math.sqrt(width * width + height * height);
    float scaleFactor = d / (emFontSize * 5f);

    float tan = ((float) height) / width;
    double radians = java.lang.Math.atan(tan);
    double degrees = (180 * radians) / java.lang.Math.PI;

    com.aspose.imaging.Matrix transform = new com.aspose.imaging.Matrix();
    transform.rotate((float) degrees);
    transform.scale(scaleFactor, scaleFactor);

    // 然后,设置变换。
    graphics.setTransform(transform);

    // 最后,将水印(粉色文本字符串)沿主对角线放置。
    graphics.drawString("WATERMARK", new com.aspose.imaging.Font(
                    "Courier New", emFontSize),
            com.aspose.imaging.Color.getLightPink(), 0, 0/*, (float)degrees*/);

    // 将带有水印的图像保存为另一个 EMF 文件。
    com.aspose.imaging.fileformats.emf.EmfImage scaledEmfImage = graphics.endRecording();
    try {
        scaledEmfImage.save(dir + "test.scaled.emf");
    } finally {
        scaledEmfImage.dispose();
    }
} finally {
    emfImage.dispose();
}

drawString(String string, Font font, Color color, int x, int y, float angle)

public void drawString(String string, Font font, Color color, int x, int y, float angle)

绘制字符串。

Parameters:

参数类型描述
字符串java.lang.String该字符串。
fontFont定义字符串文本格式的字体。
colorColor文本颜色。
xint已绘制文本左上角的 x 坐标。
yint已绘制文本左上角的 y 坐标。
anglefloat角度(以度为单位),介于转向向量与设备的 x 轴之间。转向向量与一行文本的基线平行。

excludeClip(Rectangle rect)

public void excludeClip(Rectangle rect)

更新此 Graphics 的剪辑区域,以排除由 Rectangle 结构指定的区域。

Parameters:

参数类型描述
rectRectangle指定要从剪裁区域排除的矩形的矩形结构。

excludeClip(Region region)

public void excludeClip(Region region)

更新此 Graphics 的剪辑区域,以排除由 Region 指定的区域。

Parameters:

参数类型描述
regionRegion指定要从剪裁区域排除的区域的区域。

intersectClip(RectangleF rect)

public void intersectClip(RectangleF rect)

更新此 Graphics 的剪辑区域,使其为当前剪辑区域与指定的 Rectangle 结构的交集。

Parameters:

参数类型描述
rectRectangleF与当前剪裁区域相交的矩形结构。

intersectClip(Region region)

public void intersectClip(Region region)

更新此 Graphics 的剪辑区域,使其为当前剪辑区域与指定的 Region 的交集。

Parameters:

参数类型描述
regionRegion与当前区域相交的区域。

resetClip()

public void resetClip()

重置剪辑。

multiplyTransform(Matrix matrix)

public void multiplyTransform(Matrix matrix)

将此 Graphics 的世界变换与指定的矩阵相乘。

Parameters:

参数类型描述
matrixMatrix用于乘以世界变换的矩阵。

multiplyTransform(Matrix matrix, int order)

public void multiplyTransform(Matrix matrix, int order)

按指定顺序将此 Graphics 的世界变换与指定的矩阵相乘。

Parameters:

参数类型描述
matrixMatrix用于乘以世界变换的矩阵。
orderint乘法的顺序。

translateTransform(float x, float y)

public void translateTransform(float x, float y)

通过在此 Graphics 的变换矩阵前置指定的平移来更改坐标系的原点。

Parameters:

参数类型描述
xfloat平移的 x 坐标。
yfloat平移的 y 坐标。

translateTransform(float x, float y, int order)

public void translateTransform(float x, float y, int order)

按指定顺序将指定的平移应用于此 Graphics 的变换矩阵,以更改坐标系的原点。

Parameters:

参数类型描述
xfloat平移的 x 坐标。
yfloat平移的 y 坐标。
orderint指定平移是前置还是后置到变换矩阵。

rotateTransform(float angle)

public void rotateTransform(float angle)

将指定的旋转应用于此 Graphics 的变换矩阵。

Parameters:

参数类型描述
anglefloat旋转角度(以度为单位)。

rotateTransform(float angle, PointF center, int order)

public void rotateTransform(float angle, PointF center, int order)

按指定顺序将指定的旋转应用于此 Graphics 的变换矩阵。

Parameters:

参数类型描述
anglefloat旋转角度(以度为单位)。
centerPointF旋转中心。
orderint指定旋转是后置还是前置到矩阵变换。

scaleTransform(float sx, float sy)

public void scaleTransform(float sx, float sy)

通过在对象的变换矩阵前置指定的缩放操作,将其应用于此 Graphics 的变换矩阵。

Parameters:

参数类型描述
sxfloatx 方向的缩放因子。
syfloaty 方向的缩放因子。

scaleTransform(float sx, float sy, int order)

public void scaleTransform(float sx, float sy, int order)

按指定顺序将指定的缩放操作应用于此 Graphics 的变换矩阵。

Parameters:

参数类型描述
sxfloatx 方向的缩放因子。
syfloaty 方向的缩放因子。
orderint指定缩放操作是前置还是后置到变换矩阵。

getTransform()

public Matrix getTransform()

获取世界变换。

Returns: Matrix - The transform matrix.

setTransform(Matrix transform)

public void setTransform(Matrix transform)

设置变换。

Parameters:

参数类型描述
transformMatrix新的变换矩阵。

Example: This example shows how to load a EMF image from a file and draw a text string over it.

String dir = "c:\\temp\\";

com.aspose.imaging.fileformats.emf.EmfImage emfImage = (com.aspose.imaging.fileformats.emf.EmfImage) com.aspose.imaging.Image.load(dir + "test.emf");
try {
    com.aspose.imaging.fileformats.emf.graphics.EmfRecorderGraphics2D graphics =
            com.aspose.imaging.fileformats.emf.graphics.EmfRecorderGraphics2D.fromEmfImage(emfImage);

    // 首先,获取图像尺寸
    int width = emfImage.getWidth();
    int height = emfImage.getHeight();

    // 其次,计算一个变换,以将文本字符串沿图像的主对角线放置 -
    // 从左上角到右下角。
    float emFontSize = 96f;
    float d = (float) java.lang.Math.sqrt(width * width + height * height);
    float scaleFactor = d / (emFontSize * 5f);

    float tan = ((float) height) / width;
    double radians = java.lang.Math.atan(tan);
    double degrees = (180 * radians) / java.lang.Math.PI;

    com.aspose.imaging.Matrix transform = new com.aspose.imaging.Matrix();
    transform.rotate((float) degrees);
    transform.scale(scaleFactor, scaleFactor);

    // 然后,设置变换。
    graphics.setTransform(transform);

    // 最后,将水印(粉色文本字符串)沿主对角线放置。
    graphics.drawString("WATERMARK", new com.aspose.imaging.Font(
                    "Courier New", emFontSize),
            com.aspose.imaging.Color.getLightPink(), 0, 0/*, (float)degrees*/);

    // 将带有水印的图像保存为另一个 EMF 文件。
    com.aspose.imaging.fileformats.emf.EmfImage scaledEmfImage = graphics.endRecording();
    try {
        scaledEmfImage.save(dir + "test.scaled.emf");
    } finally {
        scaledEmfImage.dispose();
    }
} finally {
    emfImage.dispose();
}