Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
906 stars 199 forks source link

Extension toJpeg() on Bgra8888Image is returning wrong picture. #471

Open giordy16 opened 1 month ago

giordy16 commented 1 month ago

Steps to Reproduce

In my app I need a play/pause button to freeze/resume the camera stream. For this reason I am building a CameraAwesomeBuilder.previewOnly Widget, where on the builder: (cameraModeState, preview) I have put a button that when is clicked shows/hides jpegImage (so it seems that the video is freezed), which is assigned like this

CameraAwesomeBuilder.previewOnly(
      onImageForAnalysis: (img) {
      if (img is Bgra8888Image) {
            jpegImage = await img.toJpeg();
          } else if (img is Nv21Image) {
            jpegImage = await img.toJpeg();
          } else if (img is Yuv420Image) {
            jpegImage = await img.toJpeg();
          } else if (img is JpegImage) {
            jpegImage = img;
          } else {
            jpegImage = null;
          }
      } 
.......

The problem is that on my iphone 14 where I am testing, img is Bgra8888Image, and thetoJpeg() gives back an image which is missing the red component (i think, overall the image is not correct).

Expected results

IMG_0073

Actual results

IMG_0074

About your device

Brand Model OS
Apple iPhone 14 17.4.1

Your flutter version

Flutter 3.19.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision 54e66469a9 (3 weeks ago) • 2024-04-17 13:08:03 -0700 Engine • revision c4cd48e186 Tools • Dart 3.3.4 • DevTools 2.31.1

dimitar-stanevv commented 3 weeks ago

I had a similar issue when using the official camera package. On iOS I had an extension method that had wrongly used a RGBA input channel order instead of BGRA. My advice is to take a picture of the red-green-blue and see if they are inverted. If yes, you may be dealing with the same issue.

image