I'm working for draw on photo android app. I'm trying to add zoom photo and drawn path together.
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
initialize()
invalidate()
}
private fun initialize() {
viewWidth = measuredWidth.toFloat()
viewHeight = measuredHeight.toFloat()
viewRect.set(0f, 0f, measuredWidth.toFloat(), measuredHeight.toFloat())
initializeBitmapMatrix()
}
private fun initializeBitmapMatrix() {
val scale = min(viewWidth / bitmapRect.width(), viewHeight / bitmapRect.height())
bitmapMatrix.setScale(scale, scale)
val translateX = (viewWidth - bitmapRect.width() * scale) / 2f
val translateY = (viewHeight - bitmapRect.height() * scale) / 2f
bitmapMatrix.postTranslate(translateX, translateY)
}
fun setBitmap(bitmap: Bitmap?) {
this.bitmap = bitmap
bitmapRect.set(
0f,
0f,
this.bitmap?.width?.toFloat() ?: 0f,
this.bitmap?.height?.toFloat() ?: 0f
)
initialize()
invalidate()
}
My gesture listener:
override fun onScale(scaleFactor: Float, focusX: Float, focusY: Float) {
bitmapMatrix.preScale(
scaleFactor,
scaleFactor,
bitmapRect.centerX(),
bitmapRect.centerY()
)
val pathComputeBounds = RectF()
path.computeBounds(pathComputeBounds, true)
paint.strokeWidth = paint.strokeWidth * scaleFactor
pathMatrix.setScale(scaleFactor, scaleFactor,
pathComputeBounds.centerX(), pathComputeBounds.centerY()
)
path.transform(pathMatrix)
invalidate()
}
When I zoom photo and path It doesn't scale correctly. You see before zoom/after zoom on photo below. How can I fix this issue?
question from:
https://stackoverflow.com/questions/65919029/how-to-scale-path-and-photo-together-in-android 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…