CamerAwesome icon indicating copy to clipboard operation
CamerAwesome copied to clipboard

Front camera photo mirrored

Open lukino563 opened this issue 4 years ago • 3 comments

Steps to Reproduce

Picture controller take photo on front camera

Expected results

Save photo with no mirror effect

Actual results

Save photo with mirror effect

About your device

Brand Model OS
Oneplus 7 Pro Android 10

lukino563 avatar Dec 28 '20 03:12 lukino563

Hi, thank you for reporting this. I put this as an enhancement.

g-apparence avatar Dec 29 '20 10:12 g-apparence

This is actually Bug, because taken photo which is saved is mirrored

lukino563 avatar Dec 29 '20 13:12 lukino563

there is pretty simple to fixed this bug,,,

you should mirror back as result file.

first, you need to install flutter plugin called image_editor.

then, look at my takePhoto function.

_takePhoto() async {
    final Directory extDir = await getTemporaryDirectory();
    final testDir =
        await Directory('${extDir.path}/toko_kece/media').create(recursive: true);
    final String filePath = '${testDir.path}/toko_kece${DateTime.now().millisecondsSinceEpoch}.jpg';
    await _pictureController.takePicture(filePath);
    // lets just make our phone vibrate
    HapticFeedback.mediumImpact();

    setState(() {});
    print("----------------------------------");
    print("TAKE PHOTO CALLED");
    final file = File(filePath);
    print("==> hastakePhoto : ${file.exists()} | path : $filePath");
    print("----------------------------------");

    if (_sensor.value == Sensors.FRONT) {
      // 1. read the image from disk into memory
      Uint8List imageBytes = await file.readAsBytes();

      // 2. flip the image on the X axis
      final ImageEditorOption option = ImageEditorOption();
      option.addOption(FlipOption(horizontal: true));
      imageBytes = await ImageEditor.editImage(image: imageBytes, imageEditorOption: option);

      // 3. write the image back to disk
      await file.delete();
      final res = await file.writeAsBytes(imageBytes);
      Navigator.of(context).pop(res);
    } else {
      Navigator.of(context).pop(file);
    }
  }

and voila,

you can preview the image after you mirror back the result from camera.

billbull21 avatar Jan 05 '21 07:01 billbull21

Thanks billbull21. You save my life!

bauloc avatar Sep 03 '22 17:09 bauloc