Pen
Inheritance: java.lang.Object, com.aspose.imaging.TransparencySupporter
public class Pen extends TransparencySupporter
定义用于绘制线条、曲线和图形的对象。
构造函数
| 构造函数 | 描述 |
|---|---|
| Pen(Color color) | 使用指定的颜色初始化 Pen 类的新实例。 |
| Pen(Color color, float width) | 使用指定的 Color 和 Pen.Width 属性初始化 Pen 类的新实例。 |
| Pen(Brush brush) | 使用指定的 Brush 初始化 Pen 类的新实例。 |
| Pen(Brush brush, float width) | 使用指定的 Brush 和 Pen.Width 初始化 Pen 类的新实例。 |
方法
Example: This example shows the creation and usage Pen objects.
此示例展示了 Pen 对象的创建和使用。示例创建了一个新的 Image 并在 Image 表面绘制 Rectangles。
// 创建 BmpOptions 的实例并设置其各项属性。
com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpOptions.setBitsPerPixel(24);
// 创建 FileCreateSource 的实例并将其指定为 BmpOptions 实例的 Source。
// 第二个布尔参数决定要创建的文件是否为 IsTemporal。
bmpOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false));
// 在指定路径创建 Image 实例
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500);
try {
// 创建 Graphics 实例并使用 Image 对象进行初始化
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
// 使用白色清除 Graphics 表面
graphics.clear(com.aspose.imaging.Color.getWhite());
// 创建一个颜色为 Red、宽度为 5 的 Pen 实例
com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 5);
// 创建 HatchBrush 实例并设置其属性
com.aspose.imaging.brushes.HatchBrush brush = new com.aspose.imaging.brushes.HatchBrush();
brush.setBackgroundColor(com.aspose.imaging.Color.getWheat());
brush.setForegroundColor(com.aspose.imaging.Color.getRed());
// 创建 Pen 实例并使用 HatchBrush 对象和宽度进行初始化
com.aspose.imaging.Pen brushedpen = new com.aspose.imaging.Pen(brush, 5);
// 通过指定 Pen 对象绘制 Rectangles
graphics.drawRectangles(pen, new com.aspose.imaging.Rectangle[]
{
new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(210, 210), new com.aspose.imaging.Size(100, 100)),
new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 110), new com.aspose.imaging.Size(100, 100)),
new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 310), new com.aspose.imaging.Size(100, 100))
});
// 通过指定 Pen 对象绘制 Rectangles
graphics.drawRectangles(
brushedpen,
new com.aspose.imaging.Rectangle[]
{
new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 110), new com.aspose.imaging.Size(100, 100)),
new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 310), new com.aspose.imaging.Size(100, 100))
});
// 保存所有更改。
image.save();
} finally {
image.dispose();
}
Pen(Color color)
public Pen(Color color)
使用指定的颜色初始化 Pen 类的新实例。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| color | Color | 一个表示此 Pen 颜色的 Color 结构。 |
Pen(Color color, float width)
public Pen(Color color, float width)
使用指定的 Color 和 Pen.Width 属性初始化 Pen 类的新实例。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| color | Color | 一个表示此 Pen 颜色的 Color 结构。 |
| 宽度 | float | 一个指示此 Pen 宽度的值。 |
Pen(Brush brush)
public Pen(Brush brush)
使用指定的 Brush 初始化 Pen 类的新实例。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| brush | Brush | 一个决定此 Pen 填充属性的 Brush。 |
Pen(Brush brush, float width)
public Pen(Brush brush, float width)
使用指定的 Brush 和 Pen.Width 初始化 Pen 类的新实例。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| brush | Brush | 一个决定此 Pen 特性的 Brush。 |
| 宽度 | float | 新 Pen 的宽度。 |
getWidth()
public float getWidth()
获取此 Pen 的宽度,单位为用于绘图的 Graphics 对象的单位。
Returns:
float - 此 Pen 的宽度。
setWidth(float value)
public void setWidth(float value)
设置此 Pen 的宽度,单位为用于绘图的 Graphics 对象的单位。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | float | 此 Pen 的宽度。 |
getStartCap()
public int getStartCap()
获取使用此 Pen 绘制的线条起始端使用的帽子样式。
Returns:
int - 表示使用此 Pen 绘制的线条起始端帽样式的 LineCap 值之一。
setStartCap(int value)
public void setStartCap(int value)
设置使用此 Pen 绘制的线条起始端使用的帽子样式。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | int | 表示使用此 Pen 绘制的线条起始端帽样式的 LineCap 值之一。 |
getEndCap()
public int getEndCap()
获取使用此 Pen 绘制的线条结束端使用的帽子样式。
Returns:
int - 表示使用此 Pen 绘制的线条结束端帽样式的 LineCap 值之一。
setEndCap(int value)
public void setEndCap(int value)
设置使用此 Pen 绘制的线条结束端使用的帽子样式。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | int | 表示使用此 Pen 绘制的线条结束端帽样式的 LineCap 值之一。 |
getDashCap()
public int getDashCap()
获取使用此 Pen 绘制的虚线中破折号结束端使用的帽子样式。
Returns:
int - 表示使用此 Pen 绘制的虚线起始和结束端帽样式的 DashCap 值之一。
setDashCap(int value)
public void setDashCap(int value)
设置使用此 Pen 绘制的虚线中破折号结束端使用的帽子样式。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | int | 表示使用此 Pen 绘制的虚线起始和结束端帽样式的 DashCap 值之一。 |
getLineJoin()
public int getLineJoin()
获取使用此 Pen 绘制的两条连续线段端点的连接样式。
Returns:
int - 表示使用此 Pen 绘制的两条连续线段端点连接样式的 LineJoin。
setLineJoin(int value)
public void setLineJoin(int value)
设置使用此 Pen 绘制的两条连续线段端点的连接样式。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | int | 一个 LineJoin,表示使用此 Pen 绘制的两条连续线段端点的连接样式。 |
getCustomStartCap()
public CustomLineCap getCustomStartCap()
获取用于此 Pen 绘制的线条起始端的自定义帽子。
Returns:
CustomLineCap - A CustomLineCap that represents the cap used at the beginning of lines drawn with this Pen.
setCustomStartCap(CustomLineCap value)
public void setCustomStartCap(CustomLineCap value)
设置用于此 Pen 绘制的线条起始端的自定义帽子。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | CustomLineCap | 一个 CustomLineCap,表示使用此 Pen 绘制的线段起始端的帽形。 |
getCustomEndCap()
public CustomLineCap getCustomEndCap()
获取用于此 Pen 绘制的线条结束端的自定义帽子。
Returns:
CustomLineCap - A CustomLineCap that represents the cap used at the end of lines drawn with this Pen.
setCustomEndCap(CustomLineCap value)
public void setCustomEndCap(CustomLineCap value)
设置用于此 Pen 绘制的线条结束端的自定义帽子。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | CustomLineCap | 一个 CustomLineCap,表示使用此 Pen 绘制的线段结束端的帽形。 |
getMiterLimit()
public float getMiterLimit()
获取斜接角处连接的厚度限制。
Returns: float - 锐角拐角处连接的厚度上限。
setMiterLimit(float value)
public void setMiterLimit(float value)
设置斜接拐角处接合厚度的上限。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | float | 锐角拐角处连接的厚度上限。 |
getAlignment()
public int getAlignment()
获取此 Pen 的对齐方式。
Returns:
int - 一个 PenAlignment,表示此 Pen 的对齐方式。
setAlignment(int value)
public void setAlignment(int value)
设置此 Pen 的对齐方式。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | int | 一个 PenAlignment,表示此 Pen 的对齐方式。 |
getTransform()
public Matrix getTransform()
获取此 Pen 的几何变换的副本。
Returns:
Matrix - A copy of the Matrix that represents the geometric transformation for this Pen.
setTransform(Matrix value)
public void setTransform(Matrix value)
设置此 Pen 的几何变换的副本。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | Matrix | 一个 Matrix 的副本,表示此 Pen 的几何变换。 |
getPenType()
public int getPenType()
获取使用此 Pen 绘制的线条样式。
Returns:
int - 一个 PenType 枚举,指定使用此 Pen 绘制的线条样式。
getColor()
public Color getColor()
获取此 Pen 的颜色。
Returns:
Color - A Color structure that represents the color of this Pen.
setColor(Color value)
public void setColor(Color value)
设置此 Pen 的颜色。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | Color | 一个 Color 结构,表示此 Pen 的颜色。 |
getBrush()
public Brush getBrush()
获取决定此 Pen 属性的 Brush。
Returns:
Brush - A Brush that determines attributes of this Pen.
setBrush(Brush value)
public void setBrush(Brush value)
设置决定此 Pen 属性的 Brush。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | Brush | 一个 Brush,决定此 Pen 的属性。 |
getDashStyle()
public int getDashStyle()
获取使用此 Pen 绘制的虚线的样式。
Returns:
int - 一个 DashStyle,表示使用此 Pen 绘制的虚线的样式。
setDashStyle(int value)
public void setDashStyle(int value)
设置使用此 Pen 绘制的虚线的样式。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | int | 一个 DashStyle,表示使用此 Pen 绘制的虚线的样式。 |
getDashOffset()
public float getDashOffset()
获取从线条起点到虚线模式起始的距离。
Returns: float - 从线段起点到虚线模式开始的距离。
setDashOffset(float value)
public void setDashOffset(float value)
设置从线条起点到虚线模式起始的距离。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | float | 从线段起点到虚线模式开始的距离。 |
getDashPattern()
public float[] getDashPattern()
获取自定义虚线和间隔的数组。
Returns: float[] - 一个实数数组,指定虚线中交替的短划线和空格的长度。
setDashPattern(float[] value)
public void setDashPattern(float[] value)
设置自定义虚线和间隔的数组。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | float[] | 一个实数数组,指定虚线中交替的短划线和空格的长度。 |
getCompoundArray()
public float[] getCompoundArray()
获取一个值数组,指定复合笔。复合笔绘制由平行线段和间隔组成的复合线。
Returns: float[] - 一个实数数组,指定复合数组。数组中的元素必须递增,且不小于 0,且不大于 1。
setCompoundArray(float[] value)
public void setCompoundArray(float[] value)
设置一个值数组,指定复合笔。复合笔绘制由平行线段和间隔组成的复合线。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| value | float[] | 一个实数数组,指定复合数组。数组中的元素必须递增,且不小于 0,且不大于 1。 |
setLineCap(int startCap, int endCap, int dashCap)
public void setLineCap(int startCap, int endCap, int dashCap)
设置决定此 Pen 绘制的线条结束端帽样式的值。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| startCap | int | 一个 LineCap,表示使用此 Pen 绘制的线段起始端的帽形样式。 |
| endCap | int | 一个 LineCap,表示使用此 Pen 绘制的线段结束端的帽形样式。 |
| dashCap | int | 一个 LineCap,表示使用此 Pen 绘制的虚线起始或结束端的帽形样式。 |
resetTransform()
public void resetTransform()
将此 Pen 的几何变换矩阵重置为单位矩阵。
multiplyTransform(Matrix matrix)
public void multiplyTransform(Matrix matrix)
将此 Pen 的变换矩阵乘以指定的 Matrix。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| matrix | Matrix | 用于乘以变换矩阵的 Matrix 对象。 |
multiplyTransform(Matrix matrix, int order)
public void multiplyTransform(Matrix matrix, int order)
按指定顺序将此 Pen 的变换矩阵乘以指定的 Matrix。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| matrix | Matrix | 用于乘以变换矩阵的 Matrix。 |
| order | int | 执行乘法操作的顺序。 |
translateTransform(float dx, float dy)
public void translateTransform(float dx, float dy)
按指定尺寸平移局部几何变换。此方法将在变换前添加平移。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| dx | float | x 方向的平移值。 |
| dy | float | y 方向的平移值。 |
translateTransform(float dx, float dy, int order)
public void translateTransform(float dx, float dy, int order)
按指定顺序按指定的尺寸平移本地几何变换。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| dx | float | x 方向的平移值。 |
| dy | float | y 方向的平移值。 |
| order | int | 应用平移的顺序(前置或后置)。 |
scaleTransform(float sx, float sy)
public void scaleTransform(float sx, float sy)
按指定因子缩放局部几何变换。此方法将在变换前添加缩放矩阵。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| sx | float | 在 x 轴方向上缩放变换的因子。 |
| sy | float | 在 y 轴方向上缩放变换的因子。 |
scaleTransform(float sx, float sy, int order)
public void scaleTransform(float sx, float sy, int order)
按指定顺序使用指定因子缩放局部几何变换。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| sx | float | 在 x 轴方向上缩放变换的因子。 |
| sy | float | 在 y 轴方向上缩放变换的因子。 |
| order | int | 指定是后置还是前置缩放矩阵的 MatrixOrder。 |
rotateTransform(float angle)
public void rotateTransform(float angle)
按指定角度旋转局部几何变换。此方法将在变换前添加旋转。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| angle | float | 旋转角度。 |
rotateTransform(float angle, int order)
public void rotateTransform(float angle, int order)
按指定顺序使用指定角度旋转局部几何变换。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| angle | float | 旋转角度。 |
| order | int | 指定是后置还是前置旋转矩阵的 MatrixOrder。 |
equals(Object o)
public boolean equals(Object o)
检查对象是否相等。
Parameters:
| 参数 | 类型 | 描述 |
|---|---|---|
| o | java.lang.Object | 其他对象。 |
Returns: boolean - 相等比较结果。
hashCode()
public int hashCode()
获取当前对象的哈希码。
Returns: int