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)
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
ConstructorsConstructorDescriptionImageInfo(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 aImageInforecord class. -
Method Summary
Modifier and TypeMethodDescriptiondoubleGet aspect ratio 获取宽高比final booleanIndicates whether some other object is "equal to" this one.longGet estimated memory size in bytes (assuming ARGB) 获取估算的内存大小(字节,假设ARGB)longfileSize()Returns the value of thefileSizerecord component.Get file size in human-readable format 获取人类可读的文件大小format()Returns the value of theformatrecord component.final inthashCode()Returns a hash code value for this object.intheight()Returns the value of theheightrecord component.booleanCheck if image is landscape orientation 检查图片是否为横向booleanCheck if image is portrait orientation 检查图片是否为纵向booleanisSquare()Check if image is square 检查图片是否为正方形longpixels()Get total pixels 获取总像素数toString()Returns a string representation of this record class.intwidth()Returns the value of thewidthrecord component.
-
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
Create image info with dimensions and format 使用尺寸和格式创建图片信息- Parameters:
width- the image width | 图片宽度height- the image height | 图片高度format- the image format | 图片格式
-
ImageInfo
Creates an instance of aImageInforecord class.
-
-
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
Get file size in human-readable format 获取人类可读的文件大小- Returns:
- formatted file size | 格式化的文件大小
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
width
-
height
-
format
-
fileSize
-