fluttercandies / flutter_wechat_camera_picker

A camera picker (take photos and videos) for Flutter projects based on WeChat's UI. It's a standalone module of wechat_assets_picker yet it can be run separately.
https://pub.dev/packages/wechat_camera_picker
Apache License 2.0
369 stars 146 forks source link

[BUG] The width and height of image captured from camera in Android is not correct #266

Closed sherlockvn closed 1 month ago

sherlockvn commented 2 months ago

Describe the bug

When i take a picture in Android simulator, and use the image returned from library, the width and height of image is not correct.

How to reproduce

import 'package:flutter/material.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';

void main() {
  runApp(const HomePage());
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<HomePage> {
  AssetEntity? selectedAsset = null;

  Future<void> selectAssets() async {
    final AssetEntity? result = await CameraPicker.pickFromCamera(
      context,
    );
    print("taking photos result: ${result}, ${result?.size}");
    if (result != null) {
      selectedAsset = result;
      if (mounted) {
        setState(() {});
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              InkWell(
                  onTap: () {
                    selectAssets();
                  },
                  child: Text('capture photo')),
              Text(
                  'width, height: ${selectedAsset?.width}, ${selectedAsset?.height}, ${selectedAsset?.orientatedWidth}, ${selectedAsset?.orientatedHeight}')
            ],
          ),
        ),
      ),
    );
  }
}

Steps to reproduce the behavior:

  1. capture image
  2. confirm the image
  3. the width and height of image is wrong

Expected behavior

The width of the image should be set to the height of the image, and the height should be set to the width.

Screenshots (If contains)

https://github.com/user-attachments/assets/703ce7aa-ed2c-4f0e-b3ff-7dc1c3dc7c4e

Version information

Additional context

AlexV525 commented 2 months ago

We don't guarantee any usage with emulators.

sherlockvn commented 2 months ago

We don't guarantee any usage with emulators.

it happens on some of real android device also, but i have one right now.

sherlockvn commented 1 month ago

Hello @AlexV525, I'm following up on our previous conversation. I've recorded a video demonstrating the issue with the camera image dimensions. The video shows that the width and height of the image from the camera are incorrect - specifically, their values appear to be swapped. Could you please take a look at this and advise on how to resolve the problem? Let me know if you need any additional information or if you'd like me to provide specific code snippets or error logs related to this issue. Thank you for your assistance.

The device information is:

https://github.com/user-attachments/assets/dbc53f87-314d-408d-ae88-835fd489bbc5

AlexV525 commented 1 month ago

Please use the latest version of both the picker, photo_manager, and camera to reproduce this so we can narrow where the root cause came from.

AlexV525 commented 1 month ago

AFAICT, this is fixed by https://github.com/fluttercandies/flutter_photo_manager/pull/1178 and will be available with photo_manager: 3.3.0. Run pub upgrade to get that version and verify if the issue persists.

sherlockvn commented 1 month ago

Thank you very much. I will check it tomorrow.