Record Class ImageInfo

java.lang.Object
java.lang.Record
cloud.opencode.base.image.ImageInfo
Record Components:
width - the image width in pixels | 图片宽度(像素)
height - the image height in pixels | 图片高度(像素)
format - the image format | 图片格式
fileSize - the file size in bytes | 文件大小(字节)

Features | 主要功能:

  • Immutable record containing image metadata - 包含图片元数据的不可变记录
  • Width, height, format, and file size information - 宽度、高度、格式和文件大小信息
  • Convenience constructors for common use cases - 常见用例的便捷构造函数

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes (format and fileSize can be null/0) - 空值安全: 是(格式和文件大小可为 null/0)

public record ImageInfo(int width, int height, ImageFormat format, long fileSize) extends Record
Image Info 图片信息

Immutable record containing image metadata.

包含图片元数据的不可变记录。

Usage Examples | 使用示例:

ImageInfo info = OpenImage.getInfo(Path.of("photo.jpg"));
System.out.println(info.width() + "x" + info.height());
System.out.println("Format: " + info.format());
System.out.println("Size: " + info.fileSize() + " bytes");
Since:
JDK 25, opencode-base-image V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    ImageInfo(int width, int height)
    Create image info with dimensions only 仅使用尺寸创建图片信息
    ImageInfo(int width, int height, ImageFormat format)
    Create image info with dimensions and format 使用尺寸和格式创建图片信息
    ImageInfo(int width, int height, ImageFormat format, long fileSize)
    Creates an instance of a ImageInfo record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Get aspect ratio 获取宽高比
    final boolean
    Indicates whether some other object is "equal to" this one.
    long
    Get estimated memory size in bytes (assuming ARGB) 获取估算的内存大小(字节,假设ARGB)
    long
    Returns the value of the fileSize record component.
    Get file size in human-readable format 获取人类可读的文件大小
    Returns the value of the format record component.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the height record component.
    boolean
    Check if image is landscape orientation 检查图片是否为横向
    boolean
    Check if image is portrait orientation 检查图片是否为纵向
    boolean
    Check if image is square 检查图片是否为正方形
    long
    Get total pixels 获取总像素数
    Returns a string representation of this record class.
    int
    Returns the value of the width record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ImageInfo

      public ImageInfo(int width, int height)
      Create image info with dimensions only 仅使用尺寸创建图片信息
      Parameters:
      width - the image width | 图片宽度
      height - the image height | 图片高度
    • ImageInfo

      public ImageInfo(int width, int height, ImageFormat format)
      Create image info with dimensions and format 使用尺寸和格式创建图片信息
      Parameters:
      width - the image width | 图片宽度
      height - the image height | 图片高度
      format - the image format | 图片格式
    • ImageInfo

      public ImageInfo(int width, int height, ImageFormat format, long fileSize)
      Creates an instance of a ImageInfo record class.
      Parameters:
      width - the value for the width record component
      height - the value for the height record component
      format - the value for the format record component
      fileSize - the value for the fileSize record component
  • Method Details

    • aspectRatio

      public double aspectRatio()
      Get aspect ratio 获取宽高比
      Returns:
      the aspect ratio (width / height) | 宽高比
    • pixels

      public long pixels()
      Get total pixels 获取总像素数
      Returns:
      the total number of pixels | 总像素数
    • estimatedMemorySize

      public long estimatedMemorySize()
      Get estimated memory size in bytes (assuming ARGB) 获取估算的内存大小(字节,假设ARGB)
      Returns:
      estimated memory size | 估算的内存大小
    • isLandscape

      public boolean isLandscape()
      Check if image is landscape orientation 检查图片是否为横向
      Returns:
      true if landscape | 如果是横向返回true
    • isPortrait

      public boolean isPortrait()
      Check if image is portrait orientation 检查图片是否为纵向
      Returns:
      true if portrait | 如果是纵向返回true
    • isSquare

      public boolean isSquare()
      Check if image is square 检查图片是否为正方形
      Returns:
      true if square | 如果是正方形返回true
    • fileSizeFormatted

      public String fileSizeFormatted()
      Get file size in human-readable format 获取人类可读的文件大小
      Returns:
      formatted file size | 格式化的文件大小
    • toString

      public 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.
    • width

      public int width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public int height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component
    • format

      public ImageFormat format()
      Returns the value of the format record component.
      Returns:
      the value of the format record component
    • fileSize

      public long fileSize()
      Returns the value of the fileSize record component.
      Returns:
      the value of the fileSize record component