Draw fixed position circles in touchable ImageView

221 Views Asked by At

I'm using TouchImageView which from com.ortiz.touch for support Bitmap zooming and drag.

I want to have a function like current Map application: put a Pin Icon once you long clicked an interested area, and you can zoom and drag the map to check around but that Pin Icon position is steady on your interesting point.

Now I can draw a circle by started from imageView.setOnLongClickListener through imageView.draw(canvas), code in imageView.setOnLongClickListener simplified as below:

zoomedRect = imageView.getZoomedRect();
currentZoom = imageView.getCurrentZoom();
Rect imageBounds = ((BitmapDrawable) imageView.getDrawable())
                        .getBounds();
// height and width of the visible (scaled) image
int scaledHeight = imageBounds.height();
int scaledWidth = imageBounds.width();

// draw circle only accept the absolute coordinate in an
// image area, so need a transfer.
currentAbsoluteTop = zoomedRect.top * scaledHeight
                        + lastClickedY_CapturedInOnTouch / currentZoom;
currentAbsoluteLeft = zoomedRect.left * scaledWidth
                        + lastClickedX_CapturedInOnTouch / currentZoom;

// save the circle coordinate to my image view.
imageView.drawCircleByXandY(currentAbsoluteLeft,
                        currentAbsoluteTop);

and draw(Canvas canvas) in MyTouchImageView(inherited from TouchImageView) is basically the reverse of proceeding transfer, and it works.

Now the problem is once I zoomed in or drag the ImageView, the circle will fly, and I noticed the behavior is different if I choose different imageVeiw.setScaleType for different ratio Bitmaps,

anyone could help?

0

There are 0 best solutions below