act*_*cah 5 flutter flutter-layout
在 iOS 上,有些照片是横向显示的(即旋转 90 度)。这似乎会随机但持续地影响某些照片(即横向显示的照片始终横向显示),并且在实时照片中更常见。我使用 image_picker ( https://pub.dev/packages/image_picker ) 来选择图像。无论用于显示照片的小部件是什么,问题仍然存在。
以这篇文章为起点,我能够通过分析不同的图像来解决这个问题,其中旋转恰好梳理出一种模式。这可能非常适合我的情况,但目前对我有用。
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());
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4570 次 |
最近记录: |