最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Flutter Camera Improving Quality - Stack Overflow

programmeradmin0浏览0评论

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:

  • Added device orientation tracking using accelerometer
  • Process images through decode → rotate → re-encode cycle
  1. Is there a way to maintain the original image quality while still implementing rotation?
  2. Im pretty sure the decode → rotate → re-encode is causing quality loss. Is there a better library to do this? Or a way to do this while keeping high quality? Photos now are under 1mb instead of the original 11mb (and you can also see this)
  3. Should I consider a different image format or processing library?
  4. Maybe moving on from jpeg can help me keep higher quality?

Device is S22 ultra if that helps. I store the image in Azure Blob Service later on.

发布评论

评论列表(0)

  1. 暂无评论