AmrJyniat
12/05/2022, 12:56 PMImage()
Composable itself?AmrJyniat
12/05/2022, 1:11 PMpointerInput
with detectTapGestures
to get the offset for the user clicked on an Image()
Composable as following:
Image(
bitmap = imageBitmap,
contentDescription = "",
modifier = Modifier.pointerInput(Unit){
detectTapGestures { offset ->
//This offset related to Image() composable
}
}
)
I can get the bitmap offset only when its size of it equals the Image()
size, but when Image()
size becomes different than the original bitmap, I get the Image()
offset not the bitmap offset.
How I can get the offset of the original bitmap?Daniele Segato
12/05/2022, 1:22 PMAmrJyniat
12/05/2022, 1:42 PMModifier.weight()
, I think the full code will elaborate more:
Column(
verticalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxSize()
) {
Image(
bitmap = bitmap,
contentDescription = "",
modifier = Modifier
.weight(1f)
.pointerInput(Unit) {
detectTapGestures { offset -> }
}
)
Divider(Modifier.background(LightGray))
Text(text = pageNum.toString())
}
Daniele Segato
12/05/2022, 1:51 PMContentScale
is Fit. You have the size of the input area from the PointerInputScope
the bitmap has width and height. That's all you needAmrJyniat
12/05/2022, 2:00 PMdetectTapGestures
gives me the Image() offsetKirill Grouchnikov
12/05/2022, 2:30 PMImage
is 400x400, and your bitmap is 1000x2000
. If the scale is fit, you compute the scale factor yourself, which is 0.2 in this case, which then used to determine the position of the bitmap inside your image - the bitmap is 200x400, offset horizontally by 100. And that would give you the next step, translating coordinates of the click from image to bitmap.