如何在Flutter中获取exif方向值

4

我正在使用Flutter开发应用程序,并且我想检索使用image_picker插件选择的图像的exif方向值。

当我运行以下代码并选择事先旋转过的图像时,方向值为null,并且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上,以查看方向值,下面是结果:

enter image description here

我正在使用可用的最新版本的image_picker插件。如何在Flutter中检索图像的exif方向值?

1个回答

2

我使用了这个函数:

  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';

解释:给定图像的path,它将返回是否需要旋转(即处于横向模式)

我也遇到了您提到的null orientation问题,我使用宽度/高度自己解决了这个问题...

我知道这似乎很奇怪...希望有人能提供更好的解决方案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接