CamerAwesome icon indicating copy to clipboard operation
CamerAwesome copied to clipboard

mirrorFrontCamera:true and Sensor.position(SensorPosition.back) ,turn iPhone left or right ,preview screen is reverse

Open NicofnCHINA opened this issue 1 year ago • 4 comments

Steps to Reproduce

mirrorFrontCamera:true and Sensor.position(SensorPosition.back) ,turn iPhone left or right ,preview screen is reverse

iOS is Error ,Android is ok

NicofnCHINA avatar Nov 28 '24 09:11 NicofnCHINA

QQ_1732999881063

I reviewed the source code and found that the mirrorFrontCamera parameter is not being used. Therefore, setting the mirrorFrontCamera parameter has no effect.

QQ_1733000521517

According to the documentation, the setMirrorFrontCamera method can be called through the state to set the front camera mirror. However, I cannot find how to call the setMirrorFrontCamera method!

QQ20241201-050044

Then I reviewed the source code regarding the implementation of setMirrorFrontCamera, and now I know how to call this method.

QQ_1733000756493

First, you need to import the package:

import 'package:camerawesome/pigeon.dart';

Then you can call the method:

// Assuming you have a reference to the state object
CameraInterface().setMirrorFrontCamera(false);

QQ20241201-050905

It works on my iPhone, I hope this can be helpful to you!

runoob-coder avatar Nov 30 '24 21:11 runoob-coder

Did you find any solution? Also having this problem

ProgUser145 avatar Dec 28 '24 20:12 ProgUser145

The same

WindBise avatar Mar 27 '25 00:03 WindBise

So for anyone who need a solution, don't mirror the front camera but save flip the image you get with image_editor

cameraAwesomeBuilder.awesome(
  onMediaCaptureEvent: (mediaCapture) async {
    if (mediaCapture.status == MediaCaptureStatus.success && mediaCapture.captureRequest.path != null) {
      final sensorPosition = mediaCapture.captureRequest.when(
        single: (single) => single.sensor.position,
      );
  
      final mediaCaptureFile = File(mediaCapture.captureRequest.path!);
  
      //on iOS, force the front camera picture to be mirrored
      if (sensorPosition == SensorPosition.front && mediaCapture.isPicture && Platform.isIOS) {
        final correctedImage = ImageEditor.editImage(
          image: imageBytes,
          imageEditorOption: ImageEditorOption()..addOption(const FlipOption()),
        );
  
        if (correctedImage != null) {
          await mediaCaptureFile.writeAsBytes(correctedImage);
          //then save your file
        }
      }
    }
  },

Adm94 avatar Apr 22 '25 10:04 Adm94

So for anyone who need a solution, don't mirror the front camera but save flip the image you get with image_editor

cameraAwesomeBuilder.awesome(
  onMediaCaptureEvent: (mediaCapture) async {
    if (mediaCapture.status == MediaCaptureStatus.success && mediaCapture.captureRequest.path != null) {
      final sensorPosition = mediaCapture.captureRequest.when(
        single: (single) => single.sensor.position,
      );
  
      final mediaCaptureFile = File(mediaCapture.captureRequest.path!);
  
      //on iOS, force the front camera picture to be mirrored
      if (sensorPosition == SensorPosition.front && mediaCapture.isPicture && Platform.isIOS) {
        final correctedImage = ImageEditor.editImage(
          image: imageBytes,
          imageEditorOption: ImageEditorOption()..addOption(const FlipOption()),
        );
  
        if (correctedImage != null) {
          await mediaCaptureFile.writeAsBytes(correctedImage);
          //then save your file
        }
      }
    }
  },

Thanks! this worked like a charm

iamnabink avatar Aug 12 '25 05:08 iamnabink