Class ImageStitch

java.lang.Object
cloud.opencode.base.image.ImageStitch

public final class ImageStitch extends Object
Image Stitching Utility 图片拼接工具类

Provides static methods for stitching multiple images together horizontally, vertically, or in a grid layout.

提供静态方法用于将多张图片水平拼接、垂直拼接或按网格排列。

Features | 主要功能:

  • Horizontal stitching with auto vertical centering - 水平拼接,自动垂直居中
  • Vertical stitching with auto horizontal centering - 垂直拼接,自动水平居中
  • Grid layout stitching by column count - 按列数网格拼接
  • Gap and background color support - 支持间距和背景色

Usage Examples | 使用示例:

// Horizontal stitch
Raster result = ImageStitch.horizontal(List.of(r1, r2, r3));

// Vertical stitch with gap and white background
Raster result = ImageStitch.vertical(List.of(r1, r2), 10, 0xFFFFFFFF);

// Grid layout
Raster result = ImageStitch.gridRaster(List.of(r1, r2, r3, r4), 2);

Security | 安全性:

  • Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具)
  • Null-safe: No (throws on null input) - 空值安全: 否(null 输入抛异常)
Since:
JDK 25, opencode-base-image V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • horizontal

      public static Raster horizontal(List<Raster> rasters)
      Stitch Rasters horizontally; height is the maximum, smaller rasters are vertically centered. 水平拼接 Raster;高度取最大,较小项垂直居中。
      Parameters:
      rasters - the rasters to stitch | 要拼接的 raster
      Returns:
      stitched RGBA_8 raster | 拼接后的 RGBA_8 raster
      Throws:
      IllegalArgumentException - if list is null or empty | 列表为 null/空时抛出
      Since:
      opencode-base-image V1.0.4
    • horizontal

      public static Raster horizontal(List<Raster> rasters, int gap, int bgArgb)
      Stitch Rasters horizontally with gap and background ARGB color. 水平拼接 Raster,带间距和背景颜色。
      Parameters:
      rasters - the rasters to stitch | 要拼接的 raster
      gap - gap between items in pixels | 间距(像素)
      bgArgb - background fill color (ARGB; use 0 for transparent) | 背景颜色(ARGB;0 为透明)
      Returns:
      stitched RGBA_8 raster | 拼接后的 RGBA_8 raster
      Throws:
      IllegalArgumentException - if invalid | 不合法时抛出
      Since:
      opencode-base-image V1.0.4
    • vertical

      public static Raster vertical(List<Raster> rasters)
      Stitch Rasters vertically; width is the maximum, smaller rasters are horizontally centered. 垂直拼接 Raster;宽度取最大,较小项水平居中。
      Parameters:
      rasters - the rasters to stitch | 要拼接的 raster
      Returns:
      stitched RGBA_8 raster | 拼接后的 RGBA_8 raster
      Since:
      opencode-base-image V1.0.4
    • vertical

      public static Raster vertical(List<Raster> rasters, int gap, int bgArgb)
      Stitch Rasters vertically with gap and background ARGB color. 垂直拼接 Raster,带间距和背景颜色。
      Parameters:
      rasters - the rasters to stitch | 要拼接的 raster
      gap - gap between items in pixels | 间距(像素)
      bgArgb - background fill color (ARGB; use 0 for transparent) | 背景颜色(ARGB;0 为透明)
      Returns:
      stitched RGBA_8 raster | 拼接后的 RGBA_8 raster
      Since:
      opencode-base-image V1.0.4
    • gridRaster

      public static Raster gridRaster(List<Raster> rasters, int columns)
      Stitch Rasters in a grid layout with the specified column count. 按指定列数将 Raster 排成网格拼接。

      The method is named gridRaster for symmetry with other Raster APIs.

      Parameters:
      rasters - the rasters to stitch | 要拼接的 raster
      columns - the number of columns (must be >= 1) | 列数(>= 1)
      Returns:
      stitched RGBA_8 raster | 拼接后的 RGBA_8 raster
      Since:
      opencode-base-image V1.0.4