ImageUtils class

图片处理器

提供三个核心功能:

  1. 生成缩略图(支持本地文件、网络URL、字节数组)
  2. 获取图片宽高
  3. 保存图片到系统相册

所有方法均通过 ImageResult 返回,不抛出异常。

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

generateThumbnail(dynamic source, {int maxWidth = 150, int maxHeight = 150, int quality = 80, ThumbnailFormat format = ThumbnailFormat.jpeg, String? cacheDir}) Future<ImageResult<Uint8List>>
生成缩略图
generateThumbnailAndSave(dynamic source, String savePath, {int maxWidth = 150, int maxHeight = 150, int quality = 80, ThumbnailFormat format = ThumbnailFormat.jpeg}) Future<ImageResult<String>>
生成缩略图并保存到指定路径
getImageSize(String path) Future<ImageResult<ImageSize>>
从文件路径或网络 URL 获取图片宽高
getImageSizeFromAsset(String assetPath) Future<ImageResult<ImageSize>>
从 Asset 资源路径获取图片宽高
getImageSizeFromBytes(Uint8List bytes) Future<ImageResult<ImageSize>>
从字节数组获取图片宽高
requestGalleryPermission() Future<ImageResult<bool>>
请求相册写入权限(Android 13+ / iOS)
saveToGallery(dynamic source, {String album = 'App Photos'}) Future<ImageResult<String>>
将图片保存到系统相册