我正在使用 Flutter 开发一个应用程序,我想检索我使用 image_picker 插件选择的图像的 exif 方向值。
当我运行下面的代码并选择一张我事先旋转过的图像时,我得到的方向值是空值,exif 数据是一个空 map 。
File file = await ImagePicker.pickImage(
source: ImageSource.gallery,
);
img.Image decodedImage = img.decodeImage(file.readAsBytesSync());
print("decodedImage.exif.orientation ${decodedImage.exif.orientation}"); // null
print("decodedImage.exif.data ${decodedImage.exif.data}"); // {}
我通过谷歌驱动器将我与此代码一起使用的图像发送到我的 mac book 以查看方向值,这就是我得到的:
我正在使用最新版本的 image_picker 插件。如何在 Flutter 中检索图像的 exif 方向值?
最佳答案
我使用了这个函数:
needRotation(String path) async {
Map<String, IfdTag> data =
await readExifFromBytes(await new File(path).readAsBytes());
return data['EXIF ExifImageWidth'].values[0] >
data['EXIF ExifImageLength'].values[0];
}
使用 import 'package:exif/exif.dart';
解释:给定图像的路径
,如果需要旋转(即处于横向模式),它将返回
我也遇到了你提到的 null orientation
问题,我自己使用宽度/高度来计算...
我知道这似乎很奇怪...希望有人能提供更好的解决方案。
关于flutter - 如何在 flutter 中检索 exif 方向值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57388773/