rakib
rakib

Reputation: 1

Some images are automatically rotated when i picked with image picker in my flutter app

I use image_picker: ^0.8.4 in my flutter app.When i wan't to pick image from gallery some images are automatically rotated .How can i solve this problem?

I try image_picker: ^0.8.5+3 and image_picker: ^0.8.6 packages.I want to pick image as it show in gallery without any rotation And i also want to keep meta data.

This is my code :

Future<XFile?> _getImage(ImageSource source, ImagePicker _picker) async {
    final pickedFile = await _picker.pickImage(source: source,imageQuality: 25);
    return pickedFile;
  }

Upvotes: 0

Views: 857

Answers (2)

Theo
Theo

Reputation: 122

If you are using video_player or any package forked from video_player e.g cached_video_player_plus to preview the video, then add this line to your pubspec.yaml:

 dependency_overrides:
      video_player_android: 2.7.1

Upvotes: 0

I encountered a similar issue with iOS devices when the Live Photo feature was enabled during capturing. The orientation of the images appeared incorrect in the app.

This approach worked for me:

Future<void> _pickImage() async {
  try {
    XFile? pickedFile = await picker.pickImage(source: ImageSource.gallery);

    if (pickedFile != null) {
      File file = File(pickedFile.path);

      // Fix the orientation if necessary
      if (Platform.isIOS) {
        file = await FlutterExifRotation.rotateImage(path: file.path);
      }

      widget.selectImage(file);
    }
  } catch (e) {
    log('Error picking image: $e');
  }
}

Dependencies

Make sure to include the required packages in your pubspec.yaml file:

dependencies:
  flutter_exif_rotation: ^0.5.1
  image: ^4.1.7

This ensures the image maintains its original orientation while keeping the metadata intact.

Upvotes: 0

Related Questions