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

The GraphicOverlay width changes when trying to save the LensEnginePreview as Bitmap #76

Closed
Mouadabdelghafouraitali opened this issue Jun 1, 2021 · 4 comments

Comments

@Mouadabdelghafouraitali
Copy link

Hi, I'm using the Gesture-Change-Background as a main source on my project, but I ran into a problem, when I try to save the LensEnginePreview as Bitmap, the GraphicOverlay image width changes :

Why this happening?

@SoftwareGift
Copy link

Could you show me your code? The possible cause is that the value range should be 0-255.We've done some post-processing on the images.Please carefully find the relevant code in the project.

@Mouadabdelghafouraitali
Copy link
Author

Mouadabdelghafouraitali commented Jun 2, 2021

@SoftwareGift thank you for your comment, please let me explain the whole scenario, because there's no way to record the video (record what happen inside LensEnginePreview), I tried to capture the view and converting it to Bitmap, every second I pass the bitmap to MediaRecorder in order to generate a video file.

The issue, is related to the Bitmap inside GraphicOverlay, I don't know why but when I try to convert the LensEnginePreview to Bitmap The image loses its width.

Regarding the code : I've tried to use the same code in the Gesture-Change-Background and the same issue happened.

View to Bitmap (Using Kotlin KTX) :

    fun view2Bitmap(lens: LensEnginePreview): Bitmap {
        return lens.drawToBitmap()
    }

View to Bitmap :

public static Bitmap view2Bitmap(final View view) {
        if (view == null) return null;
        boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
        boolean willNotCacheDrawing = view.willNotCacheDrawing();
        view.setDrawingCacheEnabled(true);
        view.setWillNotCacheDrawing(false);
        Bitmap drawingCache = view.getDrawingCache();
        Bitmap bitmap;
        if (null == drawingCache || drawingCache.isRecycled()) {
            view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
            view.buildDrawingCache();
            drawingCache = view.getDrawingCache();
            if (null == drawingCache || drawingCache.isRecycled()) {
                bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.RGB_565);
                Canvas canvas = new Canvas(bitmap);
                view.draw(canvas);
            } else {
                bitmap = Bitmap.createBitmap(drawingCache);
            }
        } else {
            bitmap = Bitmap.createBitmap(drawingCache);
        }
        view.setWillNotCacheDrawing(willNotCacheDrawing);
        view.setDrawingCacheEnabled(drawingCacheEnabled);
        return bitmap;
    }

please use one of the above code in the Gesture-Change-Background project, and you will see what I'm talking about.

Thank you

@SoftwareGift
Copy link

The pixel value of the image ranges from 0 to 255. You can write the bitmap value to a txt file and see if the value is the same as you expected.

@Mouadabdelghafouraitali
Copy link
Author

I've managed to fix this issue, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants