Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Photo broken on Android 7.0 #37

Closed
RGBvision opened this issue Jan 3, 2021 · 8 comments
Closed

Photo broken on Android 7.0 #37

RGBvision opened this issue Jan 3, 2021 · 8 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@RGBvision
Copy link

If the demo apps cannot help and there is no issue for your problem, tell us about it

Photo looks like this
Screenshot_20210103-121915

Which platform(s) does your issue occur on?

  • Android
  • Android 7.0.0
  • NVidia Shield (tablet)

Please, provide the following version numbers that your issue occurs with:

  • CLI: 7.1.1
  • Cross-platform modules: 7.1.0
  • Runtime: @nativescript/android 7.0.1
  • Plugin(s):
"dependencies": {
    "@nativescript-community/gps": "^2.1.5",
    "@nativescript-community/l": "^4.2.15",
    "@nativescript/core": "~7.1.0",
    "@nativescript/theme": "~2.3.0",
    "@nstudio/nativescript-floatingactionbutton": "^3.0.4",
    "@nstudio/nativescript-pulltorefresh": "^3.0.1",
    "@yoonit/nativescript-camera": "^2.0.0",
    "moment": "^2.29.1",
    "nativescript-app-tour": "^2.0.2",
    "nativescript-https": "^2.2.2",
    "nativescript-vibrate": "^4.0.1",
    "nativescript-windowed-modal": "file:./plugins/nativescript-windowed-modal-master/src"
  },
  "devDependencies": {
    "@nativescript/android": "7.0.1",
    "@nativescript/types": "7.1.0",
    "@nativescript/webpack": "~4.0.0",
    "node-sass": "^4.14.1"
  }

Please, tell us how to recreate the issue in as much detail as possible.

const {YoonitCamera} = require('@yoonit/nativescript-camera/Yoonit.Camera');

function cvLoaded(args) { 

    const cView = args.object; // <ContentView> in my XML
    yCam = new YoonitCamera();

    yCam.on('imageCaptured', (data) => {
        yCam.stopCapture();
        ImageSource.fromFile(data.image["path"]).then((img) => {
            const folder = knownFolders.documents().getFolder("orderPhotos").path;
            const fileName = moment().format('x') + '.jpg';
            const filePath = path.join(folder, fileName);
            const saved = img.saveToFile(filePath, "jpg");
            if (saved) {
                closeCallback(filePath);
            } else {
                
            }
        });
    });

    cView.content = yCam;

    yCam.requestPermission().then(() => {
        yCam.setLens('back');
        yCam.setOutputImageWidth("1000px");
        yCam.setOutputImageHeight("1000px");
        yCam.setSaveImageCaptured(true);
        yCam.preview();
    });
}

function onTakePhoto(args) {
    yCam.startCapture('frame');
}

@luiguild luiguild added bug Something isn't working help wanted Extra attention is needed labels Jan 4, 2021
@luiguild
Copy link
Member

luiguild commented Jan 4, 2021

Hi @RGBvision we facing the same issue specifically on Xiaomi Redmi Note 9S and we don't know how to fix it, we do not have a such device that we can reproduce this bug, you can help us?

@RGBvision
Copy link
Author

Hi @RGBvision we facing the same issue specifically on Xiaomi Redmi Note 9S and we don't know how to fix it, we do not have a such device that we can reproduce this bug, you can help us?

How can I help?

IMHO problem in image format. I faced this kind of problem before. The problem was solved by setting the correct format (YUV_420_888). But this is only a guess.

@TeruyaHaroldo
Copy link
Contributor

TeruyaHaroldo commented Jan 5, 2021

Hi @RGBvision.
In the android, we already using YUV_420_888.
In the below Kotlin code, we are converting a Image (from camera preview) to Bitmap.
The nativescript-yoonit-camera is using the android-yoonit-camera.

For more details.

fun Image.toBitmap(): Bitmap {
    val yBuffer = planes[0].buffer // Y
    val uBuffer = planes[1].buffer // U
    val vBuffer = planes[2].buffer // V

    val ySize = yBuffer.remaining()
    val uSize = uBuffer.remaining()
    val vSize = vBuffer.remaining()

    val nv21 = ByteArray(ySize + uSize + vSize)

    // U and V are swapped
    yBuffer.get(nv21, 0, ySize)
    vBuffer.get(nv21, ySize, vSize)
    uBuffer.get(nv21, ySize + vSize, uSize)

    val yuvImage = YuvImage(nv21, ImageFormat.NV21, this.width, this.height, null)
    val out = ByteArrayOutputStream()
    yuvImage.compressToJpeg(Rect(0, 0, yuvImage.width, yuvImage.height), 50, out)
    val imageBytes = out.toByteArray()
    return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
}

If we are doing something wrong, please, tell us.
With all the devices we have here is working perfectly.

@Goulartvic
Copy link
Contributor

Hi @RGBvision @luiguild @TeruyaHaroldo

I have the same behavior when I run the android-yoonit-camera demo app in Xiaomi Poco X3 so I'm going look into this problem to bring us a solution

@Goulartvic
Copy link
Contributor

Goulartvic commented Jan 12, 2021

Hi @RGBvision we just released a new feature allowing change the color encoding of the saved image in the android-yoonit-camera repo and this should resolve the bug. For tomorrow I will update the nativescript-yoonit-camera as well

https://github.com/Yoonit-Labs/android-yoonit-camera/releases/tag/2.4.0

@RGBvision
Copy link
Author

RGBvision commented Jan 23, 2021

Problem not resolved. Photo still broken. There is no setImageCaptureColorEncoding function.

@TeruyaHaroldo
Copy link
Contributor

TeruyaHaroldo commented Jan 23, 2021

Hello @RGBvision

Sorry for the delay.
This release was (much) bigger than expected.

Test the v2.2.0 for us:
https://github.com/Yoonit-Labs/nativescript-yoonit-camera/releases/tag/v2.2.0

There is no need to call any function. We changed internally the default "color encoding algorithm".
Let us know if this release resolved your problem.

@luiguild
Copy link
Member

@RGBvision you could test this new version? Your photos are ok now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants