Lock image to specific orientation #731
-
|
Hi and thank for this powerful library, I m looking for a way to lock the image in portrait or landspace format when the image is loaded and keep the same orientation when the tablet is rotated. The image preview (before loaded in the Image editor) can be displayed in portrait format but when it is loaded it change to landscape and locked into this format. I don't want to use setPreferredOrientations of flutter (user can rotate the screen) and neither the cropRotateEditor (I don't use it I the main editor). Any tips ? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Hi, That sounds like there's an EXIF orientation issue that gets lost when the editor finishes converting the image to a import 'dart:io';
import 'package:image/image.dart' as img;
Future<void> setNormalOrientation() async {
final bytes = await File('input.jpg').readAsBytes();
final image = img.decodeImage(bytes);
if (image == null) return;
// Set EXIF orientation to "normal"
image.exif.setAttribute(
'Orientation',
img.IfdValueShort(1),
);
final output = img.encodeJpg(
image,
quality: 95,
exif: image.exif,
);
await File('output.jpg').writeAsBytes(output);
} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.

Yes, but in that case you’ll need to replace the editor’s top and bottom bar with your own and interact with the editor using a
GlobalKey. You can then wrap the editor in aRotatedBoxand useOrientationBuilderor thesensor_pluspackage to detect device rotation. When the device rotates, you simply rotate the editor in the corresponding direction.