I'm experiencing image quality issues after implementing image rotation in my Flutter app (the camera code). Previously, my app produced high-quality images (~11MB), but after adding orientation handling and rotation, the image quality has significantly worsened (~1MB) with visible pixelation when zooming.
I would like some tips if I can keep the photo rotation functionality.
Previous Implementation:
final fileAsBytes = await image.readAsBytes();
final base64 = base64Encode(fileAsBytes);
FFAppState().RawPhotoList!.add({
'photo': base64,
'latitude': position.latitude.toString(),
'longitude': position.longitude.toString(),
});
}
But I added device orientation tracking and rotating:
_controller = CameraController(
cameras.first,
ResolutionPreset.max,
enableAudio: false,
);
// Image processing with rotation
Future<void> _processImageInBackground(XFile image) async {
final Uint8List fileAsBytes = await image.readAsBytes();
// Added rotation processing in isolate
final rotatedImageBytes = await compute(
rotateImageImpl,
{
'imageBytes': fileAsBytes,
'orientation': _deviceOrientation,
},
);
final base64Image = base64Encode(rotatedImageBytes);
// Store in state...
}
// Rotation implementation
Uint8List rotateImageImpl(Map<String, dynamic> data) {
final decodedImage = img.decodeImage(imageBytes);
rotatedImage = img.copyRotate(
decodedImage,
angle: rotationAngle,
interpolation: img.Interpolation.cubic,
);
final encodedImage = img.encodeJpg(rotatedImage, quality: 100);
return Uint8List.fromList(encodedImage);
}
The main changes are:
Device is S22 ultra if that helps. I store the image in Azure Blob Service later on.