从图像选择器(画廊/相机)中选择图像后,我成功地将图像旋转为横向/纵向。
这工作正常,并将继续将新图像设置为我想要的方向..
但是,我尝试使用相同的方法来旋转已选择/设置的图像,但它不起作用..
这是我正在使用的逻辑:
import 'package:image/image.dart' as img;
void _rotateImage(File file) async {
print('>>> rotating image');
try {
List<int> imageBytes = await file.readAsBytes();
final originalImage = img.decodeImage(imageBytes);
print('>>> original width: ${originalImage.width}');
img.Image fixedImage;
fixedImage = img.copyRotate(originalImage, 90);
print('>>> fixed width: ${fixedImage.width}');
final fixedFile = await file.writeAsBytes(img.encodeJpg(fixedImage));
setState(() {
print('>>> setting state');
_image = fixedFile;
});
} catch (e) {
print(e);
}
}
Run Code Online (Sandbox Code Playgroud)
我什至可以看到图像在设置状态之前正在旋转,但它仍然没有在屏幕上更新(这显示了两次尝试,而不是多次尝试)
I/flutter (18314): >>> rotating image
I/flutter (18314): >>> original width: 450
I/flutter (18314): >>> fixed width: 360 …Run Code Online (Sandbox Code Playgroud)