Class DrawOp
java.lang.Object
cloud.opencode.base.image.draw.DrawOp
Drawing Operations for Raster
Raster 绘图操作工具
Provides static methods to draw geometric shapes, lines, arrows, and text onto images. All methods return a NEW Raster and never modify the input.
提供在图像上绘制几何形状、线条、箭头和文本的静态方法。 所有方法返回新的 Raster,不修改输入图像。
Features | 主要功能:
- Draw lines with configurable thickness - 绘制可配置粗细的线条
- Draw rectangles (outline or filled) - 绘制矩形(轮廓或填充)
- Draw circles and ellipses (outline or filled) - 绘制圆和椭圆(轮廓或填充)
- Draw polygons (outline or filled) - 绘制多边形(轮廓或填充)
- Draw arrows with arrowheads - 绘制带箭头的线条
- Draw text with configurable font and color - 绘制可配置字体和颜色的文本
Usage Examples | 使用示例:
// Draw a red line
Raster result = DrawOp.line(image, 10, 10, 100, 100, Color.RED, 2);
// Draw a filled blue rectangle
Raster result = DrawOp.rect(image, 20, 20, 80, 60, Color.BLUE, 1, true);
// Draw a green circle outline
Raster result = DrawOp.circle(image, 50, 50, 30, Color.GREEN, 2, false);
// Draw text
Raster result = DrawOp.text(image, "Hello", 10, 30, new Font("Arial", Font.PLAIN, 16), Color.BLACK);
Security | 安全性:
- Thread-safe: Yes (stateless, all methods are pure functions) - 线程安全: 是(无状态,所有方法均为纯函数)
- Null-safe: No (null parameters throw IllegalArgumentException) - 空值安全: 否(null 参数抛出 IllegalArgumentException)
- Input immutability: All methods copy the input image - 输入不可变性: 所有方法复制输入图像
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
line
Draw a line on aRasterfrom(x1, y1)to(x2, y2). 在Raster上绘制从(x1, y1)到(x2, y2)的线条。Mutates the raster in place using Bresenham's line algorithm with thickness implemented as filled circles centered at every line pixel.
原地修改 raster:使用 Bresenham 算法配合在每个线条像素处填充圆来实现粗细。
- Parameters:
raster- target raster (modified in place) | 目标 raster(原地修改)x1- start x | 起点 xy1- start y | 起点 yx2- end x | 终点 xy2- end y | 终点 yargb- packed ARGB color | 打包的 ARGB 颜色thickness- line thickness in pixels (must be > 0) | 线条粗细(> 0)- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出ImageOperationException- if thickness <= 0 | 当 thickness <= 0 时抛出- Since:
- opencode-base-image V1.0.4
-
rect
public static void rect(Raster raster, int x, int y, int w, int h, int argb, int thickness, boolean fill) - Parameters:
raster- target raster (modified in place) | 目标 raster(原地修改)x- top-left x | 左上 xy- top-left y | 左上 yw- width | 宽度h- height | 高度argb- packed ARGB color | 打包的 ARGB 颜色thickness- stroke thickness (ignored when fill) | 线宽(fill 时忽略)fill- true for filled, false for outline | true 填充,false 轮廓- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出ImageOperationException- if thickness <= 0 | 当 thickness <= 0 时抛出- Since:
- opencode-base-image V1.0.4
-
circle
public static void circle(Raster raster, int cx, int cy, int radius, int argb, int thickness, boolean fill) - Parameters:
raster- target raster (modified in place) | 目标 raster(原地修改)cx- center x | 圆心 xcy- center y | 圆心 yradius- circle radius (must be > 0) | 半径(> 0)argb- packed ARGB color | 打包的 ARGB 颜色thickness- stroke thickness (ignored when fill) | 线宽(fill 时忽略)fill- true for filled, false for outline | true 填充,false 轮廓- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出ImageOperationException- if thickness <= 0 | 当 thickness <= 0 时抛出- Since:
- opencode-base-image V1.0.4
-
ellipse
public static void ellipse(Raster raster, int cx, int cy, int rx, int ry, int argb, int thickness, boolean fill) - Parameters:
raster- target raster (modified in place) | 目标 raster(原地修改)cx- center x | 椭圆中心 xcy- center y | 椭圆中心 yrx- horizontal radius | 水平半径ry- vertical radius | 垂直半径argb- packed ARGB color | 打包的 ARGB 颜色thickness- stroke thickness (ignored when fill) | 线宽(fill 时忽略)fill- true for filled, false for outline | true 填充,false 轮廓- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出ImageOperationException- if thickness <= 0 | 当 thickness <= 0 时抛出- Since:
- opencode-base-image V1.0.4
-
polygon
public static void polygon(Raster raster, int[] xPoints, int[] yPoints, int argb, int thickness, boolean fill) Draw a polygon on aRaster, outline or filled. 在Raster上绘制多边形(轮廓或填充)。Outline mode draws lines between consecutive vertices and closes the polygon. Fill mode uses an even-odd scanline fill rule.
轮廓模式连接相邻顶点并闭合;填充模式使用奇偶扫描线规则。
- Parameters:
raster- target raster (modified in place) | 目标 raster(原地修改)xPoints- x coordinates (length >= 3) | x 坐标数组(长度 >= 3)yPoints- y coordinates (length matches xPoints) | y 坐标数组(与 xPoints 等长)argb- packed ARGB color | 打包的 ARGB 颜色thickness- stroke thickness (ignored when fill) | 线宽(fill 时忽略)fill- true for filled, false for outline | true 填充,false 轮廓- Throws:
NullPointerException- if raster, xPoints, or yPoints is nullImageOperationException- if length mismatch or fewer than 3 points- Since:
- opencode-base-image V1.0.4
-
arrow
- Parameters:
raster- target raster (modified in place) | 目标 raster(原地修改)x1- start x | 起点 xy1- start y | 起点 yx2- arrowhead x | 箭头端 xy2- arrowhead y | 箭头端 yargb- packed ARGB color | 打包的 ARGB 颜色thickness- line thickness | 线条粗细- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出ImageOperationException- if thickness <= 0 | 当 thickness <= 0 时抛出- Since:
- opencode-base-image V1.0.4
-