From 04f2ed54e40b454a057f97872836d71af50b06de Mon Sep 17 00:00:00 2001 From: Yashraj Jain Date: Wed, 9 Oct 2024 11:36:42 +0530 Subject: [PATCH] fix: used png instead of jpg to maintain picture quality --- mobile/lib/pages/editing/crop.page.dart | 3 ++- mobile/lib/pages/editing/edit.page.dart | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/mobile/lib/pages/editing/crop.page.dart b/mobile/lib/pages/editing/crop.page.dart index 8bfb8c8bb9bf9..51b6e2d78e654 100644 --- a/mobile/lib/pages/editing/crop.page.dart +++ b/mobile/lib/pages/editing/crop.page.dart @@ -38,7 +38,8 @@ class CropImagePage extends HookWidget { size: 24, ), onPressed: () async { - final croppedImage = await cropController.croppedImage(); + final croppedImage = await cropController.croppedImage( + quality: FilterQuality.high); context.pushRoute( EditImageRoute( asset: asset, diff --git a/mobile/lib/pages/editing/edit.page.dart b/mobile/lib/pages/editing/edit.page.dart index 32d3aa6ba9021..c76e9f660eab7 100644 --- a/mobile/lib/pages/editing/edit.page.dart +++ b/mobile/lib/pages/editing/edit.page.dart @@ -14,6 +14,9 @@ import 'package:immich_mobile/routing/router.dart'; import 'package:immich_mobile/providers/album/album.provider.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:path/path.dart' as p; +import 'dart:async'; +import 'dart:ui' as ui; +import 'package:flutter/rendering.dart'; /// A stateless widget that provides functionality for editing an image. /// @@ -39,16 +42,18 @@ class EditImagePage extends ConsumerWidget { final Completer completer = Completer(); image.image.resolve(const ImageConfiguration()).addListener( ImageStreamListener( - (ImageInfo info, bool _) { - info.image - .toByteData(format: ImageByteFormat.png) - .then((byteData) { + (ImageInfo info, bool _) async { + try { + final ByteData? byteData = + await info.image.toByteData(format: ui.ImageByteFormat.png); if (byteData != null) { completer.complete(byteData.buffer.asUint8List()); } else { completer.completeError('Failed to convert image to bytes'); } - }); + } catch (e) { + completer.completeError('Error converting image: $e'); + } }, onError: (exception, stackTrace) => completer.completeError(exception), @@ -65,9 +70,12 @@ class EditImagePage extends ConsumerWidget { ) async { try { final Uint8List imageData = await _imageToUint8List(image); + // Use PNG format for lossless quality + final String fileName = + "${p.withoutExtension(asset.fileName)}_edited.png"; await ref.read(fileMediaRepositoryProvider).saveImage( imageData, - title: "${p.withoutExtension(asset.fileName)}_edited.jpg", + title: fileName, ); await ref.read(albumProvider.notifier).getDeviceAlbums(); Navigator.of(context).popUntil((route) => route.isFirst);