Description
I have a use case were I need to be able to programmatically zoom to a specific pixel on an image. I was hoping the zoomTo
function would help me with this, but the centroid
offset doesn't make sense to me.
I was trying to zoom to the desired pixel using the following code:
LaunchedEffect(key1 = center, key2 = zoomFactor) {
delay(1000)
val c = center?.toImage(scope.imageSize, scope.bounds)
val centroid = if (c != null) {
Offset(c.x, c.y)
} else {
Offset.Unspecified
}
zoomableState.zoomTo(
zoomFactor = zoomFactor ?: 1f,
centroid = centroid
)
Vlog.i("map", "(launch) zf[${zoomFactor}], c[${centroid}]")
}
When I do that, it just zooms to some location that doesn't match my expectations.
When I query the zoomableState.contentTransformation.centroid
it seems to keep its values fairly contained to some small numbers. Perhaps to the size of the viewport?
zf[1.0] c[Offset(362.2, 713.0)] csz[Size(3604.0, 3444.0)]
Is there some way to achieve my desired goal of centering the pixel that I want at the desired zoom level? I understand that if the pixel can't be centered, such as the image is at its bounds, the closest appropriate pixel would be centered.