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

PixelCopy is taking screenshots of layers outside of the composable #101

Closed
nubpro opened this issue Jun 17, 2023 · 5 comments · Fixed by #137
Closed

PixelCopy is taking screenshots of layers outside of the composable #101

nubpro opened this issue Jun 17, 2023 · 5 comments · Fixed by #137
Labels
bug Something isn't working

Comments

@nubpro
Copy link

nubpro commented Jun 17, 2023

I was studying how the inners of this library and discovered there's a slight problem with the drawBitmapWithPixelCopy() method which is used to capture the View into bitmap.

You can test this by modifying the library to force use drawBitmapWithPixelCopy() over view.drawToBitmap().

  1. Add throw java.lang.IllegalArgumentException("force throw") before this line and use any SDK Android Oreo or above.

  2. Copy and use the composable below.

@Composable
fun Main() {
    Box {
        val captureController = rememberCaptureController()
        val context = LocalContext.current

        Capturable(controller = captureController, onCaptured = { bitmap, error ->
            bitmap?.let {
                File(context.filesDir, "screenshot.png")
                    .writeBitmap(bitmap.asAndroidBitmap(), Bitmap.CompressFormat.PNG, 85)
            }
            Log.i("capturable", context.filesDir.toString())

            if (error != null) {
                Log.e("ERROR!", error.toString())
            }
        }) {
            Image(painter = painterResource(id = R.drawable.poster),
                contentDescription = null,
                modifier = Modifier.fillMaxWidth(),
                contentScale = ContentScale.Crop)
        }


        Button(onClick = {
            captureController.capture()
        }) {
            Text("Take a screenshot!!!!")
        }

        Text(text = "You shouldn't see me", fontSize = 140.sp, color= Color.White, modifier = Modifier.padding(15.dp))
    }
}
  1. Hit the screen button.
  2. Locate the screenshot.
  3. You will see that Capturable took a screenshot which contains the forbidden text, even though the text is not within the Capturable composable.

image

Any help is very much appreciated by our team!

@abinhho
Copy link

abinhho commented Aug 9, 2023

Same here.

@abinhho
Copy link

abinhho commented Aug 9, 2023

@nikoloz14
Copy link

Any news?

@PatilShreyas PatilShreyas added the bug Something isn't working label Oct 2, 2023
@PatilShreyas PatilShreyas linked a pull request Jan 25, 2024 that will close this issue
@PatilShreyas
Copy link
Owner

This issue has been fixed and released in version 2.0.0.

@nubpro
Copy link
Author

nubpro commented Jan 26, 2024

This issue has been fixed and released in version 2.0.0.

Amazing work. Bravo!

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

Successfully merging a pull request may close this issue.

4 participants