Class AffineTransformOp

java.lang.Object
cloud.opencode.base.image.transform.AffineTransformOp

public final class AffineTransformOp extends Object
Affine Transform Operations for Images 图像仿射变换操作

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)
BufferedImage result = AffineTransformOp.apply(image, new double[]{1,0,0, 0,1,0});

// Scale 2x
BufferedImage 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};
BufferedImage 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 Details

    • apply

      public static BufferedImage apply(BufferedImage image, double[] matrix)
      Apply an affine transform with a 6-parameter matrix. 应用 6 参数仿射变换矩阵。

      The matrix parameters [a, b, c, d, e, f] define the transform:

      x' = a*x + b*y + c
      y' = d*x + e*y + f
      

      The output image has the same dimensions as the input.

      Parameters:
      image - the source image | 源图像
      matrix - the 6-parameter affine matrix [a, b, c, d, e, f] | 6 参数仿射矩阵 [a, b, c, d, e, f]
      Returns:
      the transformed image | 变换后的图像
      Throws:
      ImageOperationException - if image is null, matrix is null or length != 6 | 当 image 为 null、matrix 为 null 或长度不为 6 时抛出
    • apply

      public static BufferedImage apply(BufferedImage image, double[] srcPoints, double[] dstPoints, int outputWidth, int outputHeight)
      Apply an affine transform derived from 3 source points mapped to 3 destination points. 应用从 3 个源点映射到 3 个目标点的仿射变换。

      Solves the 6-parameter affine system from the 3 point correspondences. Points are specified as flat arrays: [x0, y0, x1, y1, x2, y2].

      Parameters:
      image - the source image | 源图像
      srcPoints - source points [x0, y0, x1, y1, x2, y2] | 源点坐标 [x0, y0, x1, y1, x2, y2]
      dstPoints - destination points [x0, y0, x1, y1, x2, y2] | 目标点坐标 [x0, y0, x1, y1, x2, y2]
      outputWidth - the output image width | 输出图像宽度
      outputHeight - the output image height | 输出图像高度
      Returns:
      the transformed image | 变换后的图像
      Throws:
      ImageOperationException - if any input is null, points arrays have wrong length, output dimensions are not positive, or the point mapping is degenerate 当输入为 null、点数组长度不对、输出尺寸非正数或点映射退化时抛出