颤动:某些图像横向显示(旋转90度)

实际上micah

在iOS上,某些照片会横向显示(即旋转90度)。这似乎会随机但一致地影响某些照片(即,侧面显示的照片总是侧面显示),并且在Live Photos中更常发生。我使用image_picker(https://pub.dev/packages/image_picker)选择图像。无论用于显示照片的小部件如何,问题仍然存在。

问题截图

实际上micah

本文为出发点,我能够通过分析不同的图像(通过旋转巧合图案来修正它)来进行修复。这可能对我的情况非常特定,但目前对我有用。

Future<void> applyRotationFix(String originalPath) async {
  try {
    Map<String, IfdTag> data = await readExifFromFile(File(originalPath));
    print(data);

    int length = int.parse(data['EXIF ExifImageLength'].toString());
    int width = int.parse(data['EXIF ExifImageWidth'].toString());
    String orientation = data['Image Orientation'].toString();

    if (length != null && width != null && orientation != null) {
      if (length > width) {
        if (orientation.contains('Rotated 90 CW')) {
          img.Image original =
              img.decodeImage(File(originalPath).readAsBytesSync());
          img.Image fixed = img.copyRotate(original, -90);
          File(originalPath).writeAsBytesSync(img.encodeJpg(fixed));
        } else if (orientation.contains('Rotated 180 CW')) {
          img.Image original =
              img.decodeImage(File(originalPath).readAsBytesSync());
          img.Image fixed = img.copyRotate(original, -180);
          File(originalPath).writeAsBytesSync(img.encodeJpg(fixed));
        } else if (orientation.contains('Rotated 270 CW')) {
          img.Image original =
              img.decodeImage(File(originalPath).readAsBytesSync());
          img.Image fixed = img.copyRotate(original, -270);
          File(originalPath).writeAsBytesSync(img.encodeJpg(fixed));
        }
      }
    }
  } catch (e) {
    print(e.toString());
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章