Muddz / QuickShot

[Moved to MavenCentral] Capture images of any View, SurfaceView or Bitmap from your Android app in: .jpg .png or .nomedia with simple oneliner codes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting black screen capture with CameraView

PriyaSindkar opened this issue · comments

I am using CameraView Library for rendering camera surface view for video recording, picture capture results in a blank (black) screen.

Hi. Can you send me a snippet of your code?

Kotlin code:

val cameraView = findViewById<CameraView>(R.id.camera_view)
PixelShot.of(cameraView).setResultListener(object : PixelShot.PixelShotListener {
            override fun onPixelShotSuccess(path: String?) {
                Log.d("TakePicture", "picture taken success")
            }

            override fun onPixelShotFailed() {
                Log.d("TakePicture", "picture taken failed")
            }

        }).save()

xml code :

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.otaliastudios.cameraview.CameraView
        android:id="@+id/camera_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:adjustViewBounds="true"/>
</android.support.constraint.ConstraintLayout>

SurfaceView is used somewhere in CameraView library. And the code from your library is:

private Bitmap getViewBitmap() {
        Bitmap bitmap;
        if (view instanceof TextureView) {
            bitmap = ((TextureView) view).getBitmap();
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            canvas.setBitmap(null);
            return bitmap;
        } else {
            bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            canvas.setBitmap(null);
        }
        return bitmap;
    }

In my case, the control is going to the else part.
Thanks..

The way CamereaView is build is not directly compatible with PixelShot. You need to gain access to the SurfaceView object in some way before you can take a picture. Also note that saving a picture of a SurfaceVeiw in PixelShot only works from API 24

I thought so.. Thanks for your quick response.