|
|
@@ -3,6 +3,7 @@ import 'dart:typed_data';
|
|
|
|
|
|
import 'package:clean/model/asset_info.dart';
|
|
|
import 'package:clean/module/image_picker/image_picker_util.dart';
|
|
|
+import 'package:clean/utils/toast_util.dart';
|
|
|
import 'package:intl/intl.dart';
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
@@ -11,7 +12,6 @@ import 'file_utils.dart';
|
|
|
import 'package:exif/exif.dart';
|
|
|
|
|
|
class ImageUtil {
|
|
|
-
|
|
|
// 生成月份 key (用于内部存储)
|
|
|
static String getMonthKey(DateTime date) {
|
|
|
return '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
|
|
@@ -39,7 +39,8 @@ class ImageUtil {
|
|
|
}
|
|
|
|
|
|
// 获取指定月份的图片
|
|
|
- static List<AssetInfo> getMonthAssets(Map<String, List<AssetInfo>> assets, int index) {
|
|
|
+ static List<AssetInfo> getMonthAssets(
|
|
|
+ Map<String, List<AssetInfo>> assets, int index) {
|
|
|
final monthKeys = assets.keys.toList()
|
|
|
..sort((a, b) => b.compareTo(a)); // 最新的月份在前
|
|
|
|
|
|
@@ -50,10 +51,12 @@ class ImageUtil {
|
|
|
}
|
|
|
|
|
|
// 获取缩略图数据
|
|
|
- static Future<Uint8List?> getImageThumbnail(FileType type, AssetInfo asset) async {
|
|
|
+ static Future<Uint8List?> getImageThumbnail(
|
|
|
+ FileType type, AssetInfo asset) async {
|
|
|
try {
|
|
|
// 先尝试从本地读取缩略图
|
|
|
- final localThumb = await FileUtils.getThumbData(type, asset.id.substring(0, 36));
|
|
|
+ final localThumb = await FileUtils.getThumbData(
|
|
|
+ type, Platform.isIOS ? asset.id.substring(0, 36) : asset.id);
|
|
|
if (localThumb != null) {
|
|
|
return localThumb;
|
|
|
}
|
|
|
@@ -71,7 +74,8 @@ class ImageUtil {
|
|
|
try {
|
|
|
// 先尝试从本地读取
|
|
|
final assetPath = await FileUtils.getAssetPath(type);
|
|
|
- final localFile = File('$assetPath/${asset.id.substring(0, 36)}.PNG');
|
|
|
+ final localFile = File(
|
|
|
+ '$assetPath/${Platform.isIOS ? asset.id.substring(0, 36) : asset.id}.PNG');
|
|
|
if (await localFile.exists()) {
|
|
|
return localFile;
|
|
|
}
|
|
|
@@ -116,33 +120,38 @@ class ImageUtil {
|
|
|
final path = asset.originalPath;
|
|
|
// final file = await asset.file;
|
|
|
if (path != null && path.isNotEmpty) {
|
|
|
-
|
|
|
- final file = File(path);
|
|
|
- // 读取 EXIF 数据
|
|
|
- final bytes = await file.readAsBytes();
|
|
|
- final exifData = await readExifFromBytes(bytes);
|
|
|
-
|
|
|
- if (exifData.isNotEmpty) {
|
|
|
- // 相机信息
|
|
|
- details['make'] = exifData['Image Make']?.printable;
|
|
|
- details['model'] = exifData['Image Model']?.printable;
|
|
|
-
|
|
|
- // 拍摄参数
|
|
|
- // 光圈值
|
|
|
- details['aperture'] = exifData['EXIF FNumber']?.printable;
|
|
|
- // 快门速度/曝光时间
|
|
|
- details['exposureTime'] = exifData['EXIF ExposureTime']?.printable;
|
|
|
- // ISO感光度
|
|
|
- details['iso'] = exifData['EXIF ISOSpeedRatings']?.printable;
|
|
|
- // 焦距
|
|
|
- details['focalLength'] = exifData['EXIF FocalLengthIn35mmFilm']?.printable;
|
|
|
-
|
|
|
- // GPS 信息
|
|
|
- if (exifData.containsKey('GPS GPSLatitude') &&
|
|
|
- exifData.containsKey('GPS GPSLongitude')) {
|
|
|
- details['latitude'] = exifData['GPS GPSLatitude']?.printable;
|
|
|
- details['longitude'] = exifData['GPS GPSLongitude']?.printable;
|
|
|
+ try {
|
|
|
+ final file = File(path);
|
|
|
+ // 读取 EXIF 数据
|
|
|
+ final bytes = await file.readAsBytes();
|
|
|
+ final exifData = await readExifFromBytes(bytes);
|
|
|
+
|
|
|
+ if (exifData.isNotEmpty) {
|
|
|
+ // 相机信息
|
|
|
+ details['make'] = exifData['Image Make']?.printable;
|
|
|
+ details['model'] = exifData['Image Model']?.printable;
|
|
|
+
|
|
|
+ // 拍摄参数
|
|
|
+ // 光圈值
|
|
|
+ details['aperture'] = exifData['EXIF FNumber']?.printable;
|
|
|
+ // 快门速度/曝光时间
|
|
|
+ details['exposureTime'] = exifData['EXIF ExposureTime']?.printable;
|
|
|
+ // ISO感光度
|
|
|
+ details['iso'] = exifData['EXIF ISOSpeedRatings']?.printable;
|
|
|
+ // 焦距
|
|
|
+ details['focalLength'] =
|
|
|
+ exifData['EXIF FocalLengthIn35mmFilm']?.printable;
|
|
|
+
|
|
|
+ // GPS 信息
|
|
|
+ if (exifData.containsKey('GPS GPSLatitude') &&
|
|
|
+ exifData.containsKey('GPS GPSLongitude')) {
|
|
|
+ details['latitude'] = exifData['GPS GPSLatitude']?.printable;
|
|
|
+ details['longitude'] = exifData['GPS GPSLongitude']?.printable;
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (e) {
|
|
|
+ print('读取 EXIF 数据失败: $e');
|
|
|
+ ToastUtil.show('获取照片详情失败');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -150,6 +159,7 @@ class ImageUtil {
|
|
|
return details;
|
|
|
} catch (e) {
|
|
|
print('获取照片详情失败: $e');
|
|
|
+
|
|
|
return {};
|
|
|
}
|
|
|
}
|
|
|
@@ -196,4 +206,4 @@ class ImageUtil {
|
|
|
}
|
|
|
return '${value}s';
|
|
|
}
|
|
|
-}
|
|
|
+}
|