Class AffineTransformOp
Provides affine transformations on images including translation, rotation, scaling, shearing and arbitrary 6-parameter affine mappings. Supports both direct matrix specification and 3-point correspondence mapping.
提供图像仿射变换操作,包括平移、旋转、缩放、错切以及任意 6 参数仿射映射。 同时支持直接矩阵指定和 3 点对应映射。
Features | 主要功能:
- Apply 6-parameter affine transform matrix [a,b,c,d,e,f] - 应用 6 参数仿射变换矩阵 [a,b,c,d,e,f]
- Map 3 source points to 3 destination points - 将 3 个源点映射到 3 个目标点
- Bilinear interpolation for high-quality output - 双线性插值保证高质量输出
Usage Examples | 使用示例:
// Identity transform (no change)
Raster result = AffineTransformOp.apply(image, new double[]{1,0,0, 0,1,0});
// Scale 2x
Raster scaled = AffineTransformOp.apply(image, new double[]{2,0,0, 0,2,0});
// 3-point mapping
double[] src = {0,0, 100,0, 0,100};
double[] dst = {10,10, 210,10, 10,210};
Raster mapped = AffineTransformOp.apply(image, src, dst, 220, 220);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
- Null-safe: No (validates input, throws on null) - 空值安全: 否(验证输入,null 时抛出异常)
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
apply
Apply an affine transform with a 6-parameter matrix to aRaster. 对Raster应用 6 参数仿射变换矩阵。The matrix [a, b, c, d, e, f] defines x' = a*x + b*y + c, y' = d*x + e*y + f. Output dimensions match the source. Bilinear interpolation is used and the output preserves the source pixel format (RGBA_8 / BGRA_8 retain transparency for out-of-bounds samples; otherwise out-of-bounds samples are black).
矩阵 [a, b, c, d, e, f] 定义 x' = a*x + b*y + c, y' = d*x + e*y + f。 输出尺寸与源相同。使用双线性插值,输出保留源像素格式 (RGBA_8 / BGRA_8 在越界采样时保持透明,其他格式越界采样为黑色)。
- Parameters:
raster- the source raster | 源 rastermatrix- the 6-parameter affine matrix | 6 参数仿射矩阵- Returns:
- the transformed raster (same format as source) | 变换后的 raster(与源格式相同)
- Throws:
NullPointerException- if any argument is null | 任一参数为 null 时抛出ImageOperationException- if matrix length != 6 or contains non-finite | 当矩阵长度不为 6 或非有限时抛出- Since:
- opencode-base-image V1.0.4
-
apply
- Parameters:
raster- the source raster | 源 rastermatrix- the 6-parameter affine matrix | 6 参数仿射矩阵dst- optional output raster (same format as source); may be null | 可选输出 raster(与源格式相同),可为 null- Returns:
- the transformed raster | 变换后的 raster
- Throws:
NullPointerException- if raster or matrix is null | 当 raster 或矩阵为 null 时抛出ImageOperationException- if matrix length != 6 or contains non-finite | 当矩阵长度不为 6 或非有限时抛出- Since:
- opencode-base-image V1.0.4
-
apply
public static Raster apply(Raster raster, double[] srcPoints, double[] dstPoints, int outputWidth, int outputHeight) Apply an affine transform to aRasterfrom 3 source/destination point pairs. 通过 3 个源/目标点对对Raster应用仿射变换。- Parameters:
raster- the source raster | 源 rastersrcPoints- source points [x0, y0, x1, y1, x2, y2] | 源点坐标dstPoints- destination points [x0, y0, x1, y1, x2, y2] | 目标点坐标outputWidth- the output raster width | 输出 raster 宽度outputHeight- the output raster height | 输出 raster 高度- Returns:
- the transformed raster (same format as source) | 变换后的 raster(与源格式相同)
- Throws:
NullPointerException- if any input is null | 任一输入为 null 时抛出ImageOperationException- if points length is wrong, dimensions are non-positive, or the mapping is degenerate | 长度不对、尺寸非正或映射退化时抛出- Since:
- opencode-base-image V1.0.4
-