Kapil Yadav
10/23/2023, 6:34 AMDialog(
onDismissRequest = {},
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = true,
usePlatformDefaultWidth = false)
) {
val dialogContext = LocalContext.current
AndroidView(
factory = { context ->
context.let {
StickyViewForShare(
context = dialogContext,
onBitMapCreated = { },
stickyModel = stickyData,
viberHeaderData = data,
onCloseClick = {
}
)
}
},
modifier = Modifier.fillMaxSize()
)
}
So I want to convert StickyViewForShare view to bitmap.
in StickyViewForShare
I used ComposeView and then inside that my compose content.
Now problem is, the bitmap I get isn't of the StickyViewForShare, its of the window active under dialog.
Please any lead on this ????private fun createBitmapFromView(view: View, width: Int, height: Int, window: Window, onComplete: (Bitmap)->Unit) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Above Android O, use PixelCopy
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val location = IntArray(2)
view.getLocationInWindow(location)
PixelCopy.request(window,
Rect(location[0], location[1], location[0] + width, location[1] + height),
bitmap,
{
if (it == PixelCopy.SUCCESS) {
println("Aaya hu mai Oreo pixel copy success ")
onComplete.invoke(bitmap)
} else {
println("Aaya hu mai Oreo pixel copy failed ")
println("YULU "+ it)
}
},
Handler(Looper.getMainLooper()) )
} else {
view.layoutParams = LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
)
view.measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
)
view.layout(0, 0, width, height)
val canvas = Canvas()
val bitmap =
Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.RGB_565)
canvas.setBitmap(bitmap)
view.draw(canvas)
onComplete.invoke(bitmap)
println("Aaya hu mai Nought pixel copy success ")
}
}
function to convert view into bitmap.