-
Notifications
You must be signed in to change notification settings - Fork 32
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
Need SubsamplingScaleImageView.visibleFileRect(Rect fRect) analog #89
Comments
This sounds similar to #64 (comment) maybe the solution works for you as well? |
Thanks, but this is different. Composable-to-bitmap api writes to a bitmap a piece of the screen and I need a piece of the original bitmap. |
Hmm, I would have expected telephoto/zoomable/src/commonMain/kotlin/me/saket/telephoto/zoomable/RealZoomableState.kt Lines 179 to 184 in 7015d6e
Are its numbers significantly off? |
I made some experiments. If I pan to top left corner, then visible bitmap crop area will be If I pan to bottom right corner , then visible bitmap crop area will be So I finnaly succedded to get this area correctly with the following code getCroppedRectFromBitmap(
sourceBitmap,
contentWidth = zoomableState.contentTransformation.contentSize.width,
contentHeight = zoomableState.contentTransformation.contentSize.height,
scaledRectWidth = imageContentSizeInDp.width.value * density.density,
scaledRectHeight = imageContentSizeInDp.height.value * density.density,
scaledOffsetX = zoomableState.contentTransformation.offset.x,
scaledOffsetY = zoomableState.contentTransformation.offset.y,
scaleX = zoomableState.contentTransformation.scale.scaleX,
scaleY = zoomableState.contentTransformation.scale.scaleY,
)
fun getCroppedRectFromBitmap(
sourceBitmap:Bitmap,
scaledRectWidth: Float,
scaledRectHeight: Float,
scaledOffsetX: Float,
scaledOffsetY: Float,
scaleX: Float,
scaleY: Float,
): Bitmap? {
val scale = max(scaleX, scaleY)
val left = abs(scaledOffsetX / scale).toInt()
val top = abs(scaledOffsetY / scale).toInt()
var width = (scaledRectWidth / scale).toInt()
width = min(width, sourceBitmap.width - left)
var height = (scaledRectHeight / scale).toInt()
height = min(height, sourceBitmap.height - top)
return Bitmap.createBitmap(sourceBitmap, left, top, width, height)
} |
I need to get the visible area Rect of the source bitmap to save it into another one (android wallpapers app).
It seems I need something like davemorissey SubsamplingScaleImageView.visibleFileRect(Rect fRect) in ZoomableState.
I tried to look at contentTransformation & transformedContentBounds, but did not succeded in getting the exact rect which is shown.
It would be nice if you add such method.
The text was updated successfully, but these errors were encountered: