Record Class ExifInfo

java.lang.Object
java.lang.Record
cloud.opencode.base.image.exif.ExifInfo
Record Components:
orientation - EXIF orientation value (1-8), 0 if unknown | EXIF 方向值 (1-8),未知为 0
cameraMake - camera manufacturer, nullable | 相机制造商,可为 null
cameraModel - camera model, nullable | 相机型号,可为 null
dateTime - date/time the photo was taken, nullable | 拍摄日期时间,可为 null
latitude - GPS latitude in decimal degrees, nullable | GPS 纬度(十进制度),可为 null
longitude - GPS longitude in decimal degrees, nullable | GPS 经度(十进制度),可为 null
imageWidth - image width in pixels, nullable | 图片宽度(像素),可为 null
imageHeight - image height in pixels, nullable | 图片高度(像素),可为 null
software - software used to create the image, nullable | 创建图片的软件,可为 null

public record ExifInfo(int orientation, String cameraMake, String cameraModel, Instant dateTime, Double latitude, Double longitude, Integer imageWidth, Integer imageHeight, String software) extends Record
EXIF Information Record EXIF 信息记录

Immutable record holding EXIF metadata extracted from a JPEG image. All fields except orientation are nullable, representing absent metadata.

不可变记录,保存从 JPEG 图片中提取的 EXIF 元数据。 除 orientation 外所有字段均可为 null,表示元数据缺失。

Features | 主要功能:

  • Hold parsed EXIF metadata - 保存解析后的 EXIF 元数据
  • GPS presence check - GPS 存在性检查
  • Rotation necessity check - 旋转必要性检查
  • Factory method for empty/absent EXIF - 空/缺失 EXIF 的工厂方法

Usage Examples | 使用示例:

ExifInfo info = ExifOp.read(path);
if (info.hasGps()) {
    System.out.println("Location: " + info.latitude() + ", " + info.longitude());
}
if (info.needsRotation()) {
    BufferedImage corrected = ExifOp.autoOrient(image, info.orientation());
}

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-image V2.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ExifInfo

      public ExifInfo(int orientation, String cameraMake, String cameraModel, Instant dateTime, Double latitude, Double longitude, Integer imageWidth, Integer imageHeight, String software)
      Creates an instance of a ExifInfo record class.
      Parameters:
      orientation - the value for the orientation record component
      cameraMake - the value for the cameraMake record component
      cameraModel - the value for the cameraModel record component
      dateTime - the value for the dateTime record component
      latitude - the value for the latitude record component
      longitude - the value for the longitude record component
      imageWidth - the value for the imageWidth record component
      imageHeight - the value for the imageHeight record component
      software - the value for the software record component
  • Method Details

    • hasGps

      public boolean hasGps()
      Check if GPS coordinates are present 检查是否存在 GPS 坐标
      Returns:
      true if both latitude and longitude are present | 当纬度和经度都存在时返回 true
    • needsRotation

      public boolean needsRotation()
      Check if the image needs rotation based on EXIF orientation 根据 EXIF 方向检查图片是否需要旋转
      Returns:
      true if orientation is not normal (not 1) | 当方向不正常(非 1)时返回 true
    • empty

      public static ExifInfo empty()
      Create an empty ExifInfo representing absent or unparseable EXIF data 创建一个空的 ExifInfo,表示缺失或无法解析的 EXIF 数据
      Returns:
      an ExifInfo with orientation=0 and all nullable fields null | orientation=0 且所有可空字段为 null 的 ExifInfo
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • orientation

      public int orientation()
      Returns the value of the orientation record component.
      Returns:
      the value of the orientation record component
    • cameraMake

      public String cameraMake()
      Returns the value of the cameraMake record component.
      Returns:
      the value of the cameraMake record component
    • cameraModel

      public String cameraModel()
      Returns the value of the cameraModel record component.
      Returns:
      the value of the cameraModel record component
    • dateTime

      public Instant dateTime()
      Returns the value of the dateTime record component.
      Returns:
      the value of the dateTime record component
    • latitude

      public Double latitude()
      Returns the value of the latitude record component.
      Returns:
      the value of the latitude record component
    • longitude

      public Double longitude()
      Returns the value of the longitude record component.
      Returns:
      the value of the longitude record component
    • imageWidth

      public Integer imageWidth()
      Returns the value of the imageWidth record component.
      Returns:
      the value of the imageWidth record component
    • imageHeight

      public Integer imageHeight()
      Returns the value of the imageHeight record component.
      Returns:
      the value of the imageHeight record component
    • software

      public String software()
      Returns the value of the software record component.
      Returns:
      the value of the software record component