Capturable: Can't get the Bitmap when Capturable includes Network image

Hello!! When I press the button where I have the controller.capture function, I get the same error all the time, at first I thought I had something wrong configured, I cloned the repository to see the example, and I had it similar, but the example does not give me the same error as me

Error obtained

java.lang.IllegalArgumentException: Software rendering doesn't support hardware bitmaps

Capturable

                        Capturable(
                            modifier = Modifier.constrainAs(ivLetterImage) {
                                linkTo(parent.start, parent.end)
                                linkTo(parent.top, tvAddressee.top)
                                width = Dimension.fillToConstraints
                            },
                            controller = controller,
                            onCaptured = { bitmap, error ->
                                //ticketBitmap = bitmap
                                error
                                context.share(
                                    nameOfImage = letters,
                                    message = "",
                                    bitmap = bitmap?.asAndroidBitmap().orEmpty()
                                )
                            }
                        ) {
                            LetterImage(
                                addressee = addressee.value.text,
                                message = message.value.text,
                                sender = sender.value.text,
                                letterImage = letterImage
                            )
                        }

LetterImage Composable

@ExperimentalFoundationApi
@Composable
fun LetterImage(
    modifier: Modifier = Modifier,
    addressee: String,
    message: String,
    sender: String,
    letterImage: String
) {

    ConstraintLayout(
        modifier = modifier
    ) {

        val (
            ivLetter,
            tvAddressee,
            tvMessage,
            tvSender
        ) = createRefs()

        NetworkImage(
            modifier = Modifier
                .wrapContentHeight()
                .fillMaxWidth()
                .constrainAs(ivLetter) {
                    linkTo(parent.start, parent.end)
                    linkTo(parent.top, parent.bottom)
                },
            contentScale = ContentScale.Crop,
            url = letterImage,
            builder = {
                crossfade(true)
            }
        )

        Text(
            text = addressee,
            maxLines = 1,
            color = lightGreyPastel,
            fontWeight = FontWeight.Bold,
            style = TypographyNook.h6,
            modifier = Modifier
                .padding(top = 30.dp, start = 40.dp)
                .constrainAs(tvAddressee) {
                    start.linkTo(parent.start)
                    top.linkTo(ivLetter.top)
                }
        )

        Text(
            text = message,
            maxLines = 7,
            color = lightGreyPastel,
            fontWeight = FontWeight.Bold,
            style = TypographyNook.h6,
            modifier = Modifier
                .padding(top = 20.dp, start = 60.dp, end = 60.dp)
                .constrainAs(tvMessage) {
                    linkTo(parent.start, parent.end)
                    top.linkTo(tvAddressee.bottom)
                    bottom.linkTo(tvSender.top)
                }
        )

        Text(
            text = sender, //16,
            maxLines = 1,
            color = lightGreyPastel,
            fontWeight = FontWeight.Bold,
            style = TypographyNook.h6,
            modifier = Modifier
                .padding(top = 20.dp, bottom = 30.dp, end = 40.dp)
                .constrainAs(tvSender) {
                    end.linkTo(parent.end)
                    linkTo(tvMessage.bottom, parent.bottom)
                }
        )

    }

}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@Jeluchu This has been released in v1.0.2

As mentioned here: https://github.com/PatilShreyas/Capturable/pull/9#issue-1111822044

Crash IllegalArgumentException: Software rendering doesn't support hardware bitmaps on capturing Bitmap of Composable including network image (such as Glide, Picasso, Coil). This issue was occurring on devices above Android Oreo (API 26+) in which drawing Bitmap from Canvas causes such issues while drawing hardware-generated Bitmap (i.e. image loaded from the network). The solution is to use PixelCopy API on the devices having API version 26+ for generating Bitmap from View by copying “specific” Surface area pixels into the Bitmap.

Thanks, @Jeluchu for this helpful finding and for making it better 😀. This will be released in v1.0.2

Thanks @Jeluchu for the detailed info, will look into it.

The log which you shared here is about NullPointerException occurring in your code which is related to uriString variable.

For saving bitmap, you can refer to this code

fun saveBitmap(context: Context, bitmap: Bitmap, filename: String = DEFAULT_FILENAME): Uri? {
    val contentValues = ContentValues().apply {
        put(MediaStore.MediaColumns.DISPLAY_NAME, filename)
        put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)
        }
    }

    val contentResolver = context.contentResolver

    val imageUri: Uri? = contentResolver.insert(
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
        contentValues
    )

    return imageUri.also {
        val fileOutputStream = imageUri?.let { contentResolver.openOutputStream(it) }
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
        fileOutputStream?.close()
    }
}

Closing this issue since this doesn’t looks like associated with the library.