-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
colors are inverted #193
Comments
Can you try setting white background before capturable modifier? |
I found issue is only for background, content is being captured properly, I think issue comes from part of asAndroidBitmap because bitmap before this part is captured fine |
Wonder if we can use pixel copy ? |
Try to set background attribute to the last, it may be worked! I met a similar problem that my background is turned to black. Box(
modifier = Modifier
.padding(top = 20.dp, start = 32.dp, end = 32.dp)
.aspectRatio(boxRatio)
.background(backgroundColor)
.capturable(captureController)
) {
...
} To solve this problem, I found another solution using NEW VERSION of Compose UI: Compose to Bitmap val coroutineScope = rememberCoroutineScope()
val graphicsLayer = rememberGraphicsLayer()
Box(
modifier = Modifier
.drawWithContent {
// call record to capture the content in the graphics layer
graphicsLayer.record {
// draw the contents of the composable into the graphics layer
this@drawWithContent.drawContent()
}
// draw the graphics layer on the visible canvas
drawLayer(graphicsLayer)
}
.clickable {
coroutineScope.launch {
val bitmap = graphicsLayer.toImageBitmap()
// do something with the newly acquired bitmap
}
}
.background(Color.White) // THE LAST
) {
Text("Hello Android", fontSize = 26.sp)
} So I set background which is below to capturable, it is turned to normal! Box(
modifier = Modifier
.padding(top = 20.dp, start = 32.dp, end = 32.dp)
.aspectRatio(boxRatio)
.capturable(captureController)
.background(backgroundColor)
) {
...
}
...
Button(onClick = {
coroutineScope.launch {
try {
val bitmapAsync = captureController.captureAsync().await()
val bitmap = bitmapAsync.asAndroidBitmap()
val bytes = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
val path = MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, "Title", null)
val sendIntent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_STREAM, Uri.parse(path))
type = "image/JPEG"
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(context, shareIntent, null)
} catch (error: Throwable) {
// Error occurred, do something.
}
}
}) Hope to this solution is helpful for you! |
Thanks @qaz5823091 for sharing your learnings. |
Probably fixed in |
I found after capture colors are inverted, i.e. white became black and so on
snippet:
The text was updated successfully, but these errors were encountered: