I tried to created view with image (floor plan) and marker on it. I need to add marker in place, where user tapped. This marker should be another view, which not scaled, when user scales ImageView, but should stay on placed coordinates, when user drags view or scale it. So it should work as on Google Maps: big image as background and picker, which user can place anywhere. I tried to use PhotoView enter link description here, because it supports scaling, dragging. But I didn't can create it in this configuration. I tried to constrait picker to photoview by from left, right, top, bottom. Bu PhotoView modify image inside it, and when I scale or drag it, my picker "fly" outside of screen. Then I tried to merge picker with image in PhotoView, but This way is not so proper, because when user scales image, picker scales with it (it is a part of image).
So, maybe somebody does something like this?
My solution:
var lastX = -1F
var lastY = -1F
photoview.setOnPhotoTapListener { _, x, y ->
lastX = (x * originalImage.width) - picker.width / 2
lastY = (y * originalImage.height) - picker.height
photoview.setImageBitmap(originalImage.mergeWith(picker, lastX, lastY))
}
photoview.setOnScaleChangeListener { _, _, _ ->
if (lastX != -1F && lastY != -1F) {
photoview.setImageBitmap(originalImage.mergeWith(picker, lastX, lastY))
}
}
function for merging image and picker:
fun Bitmap.mergeWith(bp: Bitmap, x: Float, y: Float): Bitmap {
val result = createBitmap(
if (width > bp.width) width else bp.width,
if (height > bp.height) height else bp.height,
config
)
val canvas = Canvas(result)
canvas.drawBitmap(this, 0F, 0F, null)
canvas.drawBitmap(bp, x, y, null)
return result
}