Class ExifOp
Pure Java EXIF parser for JPEG images. Reads EXIF metadata from the APP1 segment without any third-party dependencies. Supports reading orientation, camera info, GPS coordinates, date/time, and software tags.
纯 Java 实现的 JPEG 图片 EXIF 解析器。从 APP1 段读取 EXIF 元数据, 不依赖任何第三方库。支持读取方向、相机信息、GPS 坐标、日期时间和软件标签。
Features | 主要功能:
- Read EXIF metadata from JPEG files or byte arrays - 从 JPEG 文件或字节数组读取 EXIF 元数据
- Strip EXIF tags selectively or entirely - 选择性或完全清除 EXIF 标签
- Auto-orient images based on EXIF orientation - 根据 EXIF 方向自动旋转图片
- Pure Java implementation, no third-party dependencies - 纯 Java 实现,无第三方依赖
Usage Examples | 使用示例:
// Read EXIF from file
ExifInfo info = ExifOp.read(Path.of("photo.jpg"));
// Read EXIF from bytes
ExifInfo info = ExifOp.read(jpegBytes);
// Strip all EXIF data
byte[] clean = ExifOp.strip(jpegBytes, ExifTag.ALL);
// Auto-orient image
Raster corrected = ExifOp.autoOrient(image, info.orientation());
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具)
- Null-safe: No (throws NullPointerException on null input) - 空值安全: 否(null 输入抛出 NullPointerException)
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic RasterautoOrient(Raster raster, int orientation) Auto-orient aRasterbased on EXIF orientation value.static ExifInforead(byte[] jpegBytes) Read EXIF metadata from JPEG bytes 从 JPEG 字节数组读取 EXIF 元数据static ExifInfoRead EXIF metadata from a JPEG file 从 JPEG 文件读取 EXIF 元数据static byte[]Strip EXIF tags from JPEG bytes 从 JPEG 字节数组中清除 EXIF 标签
-
Method Details
-
read
Read EXIF metadata from a JPEG file 从 JPEG 文件读取 EXIF 元数据- Parameters:
path- the path to the JPEG file | JPEG 文件路径- Returns:
- the parsed EXIF info, or empty if not a JPEG or no EXIF | 解析的 EXIF 信息,非 JPEG 或无 EXIF 则返回空
- Throws:
ImageIOException- if the file cannot be read | 当文件无法读取时NullPointerException- if path is null | 当 path 为 null 时
-
read
Read EXIF metadata from JPEG bytes 从 JPEG 字节数组读取 EXIF 元数据- Parameters:
jpegBytes- the JPEG image bytes | JPEG 图片字节数组- Returns:
- the parsed EXIF info, or empty if not a JPEG or no EXIF | 解析的 EXIF 信息,非 JPEG 或无 EXIF 则返回空
- Throws:
NullPointerException- if jpegBytes is null | 当 jpegBytes 为 null 时
-
strip
Strip EXIF tags from JPEG bytes 从 JPEG 字节数组中清除 EXIF 标签If
ExifTag.ALLis included, the entire APP1 segment is removed. Otherwise, only the specified tag categories are zeroed out within the existing EXIF structure.如果包含
ExifTag.ALL,则移除整个 APP1 段。 否则,仅在现有 EXIF 结构中将指定标签类别清零。- Parameters:
jpegBytes- the JPEG image bytes | JPEG 图片字节数组tags- the tag categories to strip | 要清除的标签类别- Returns:
- the JPEG bytes with specified tags stripped | 清除指定标签后的 JPEG 字节数组
- Throws:
NullPointerException- if jpegBytes or tags is null | 当 jpegBytes 或 tags 为 null 时
-
autoOrient
Auto-orient aRasterbased on EXIF orientation value. 根据 EXIF 方向值自动旋转Raster。Pure-Java rotation/flip. Returns a freshly allocated raster of the same
PixelFormatas the source. For orientation1(normal) the source is returned unchanged.纯 Java 实现的旋转/翻转。返回与源相同
PixelFormat的新 raster; 方向 1 时直接返回源。Supported orientations | 支持的方向: 1=Normal, 2=FlipH, 3=Rotate180, 4=FlipV, 5=FlipH+Rotate90CW, 6=Rotate90CW, 7=FlipH+Rotate90CCW, 8=Rotate90CCW. Other values return the source unchanged.
- Parameters:
raster- the source raster | 源 rasterorientation- EXIF orientation (1-8) | EXIF 方向(1-8)- Returns:
- the correctly oriented raster | 正确方向的 raster
- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出- Since:
- opencode-base-image V1.0.4
-