0

Please help me

I'm developing an android application to display a pinch zoom-able and drag-able bit map in a image view(Image view's boundaries are same as device screen size). I'm only zooming the bit map and show it in the image view

What I want is

When click a place on the device screen get that X an Y positions and draw a dot exactly in the place where I clicked on the bitmap Its like marking your location on the bit map

Here is a descriptive image (Sorry I couldn't upload it to here because i have low reputation)

http://www4.picturepush.com/photo/a/9321682/img/9321682.jpg

as the image displays i want to get the x2, y2 positions of image view and draw the red dot in x1,y1 position on the bit map

It will be very help full for me if you can give me some codes or advice

thank you

2 Answers2

1

I have gone through same problem and got resolved.

try this,

  1. *Get touch points x, y *

       int x = (int) event.getX();
       int y = (int) event.getY();
    

2. Calculate inverse matrix

            // calculate inverse matrix
            Matrix inverse = new Matrix();

3. Get your ImageView matrix getImageMatrix().invert(inverse);

4. Map your co-ordinates to actual image

        // map touch point from ImageView to image
        float[] touchPoint = new float[] { event.getX(), event.getY() };
        inverse.mapPoints(touchPoint);

*4. Get your actual x, y of image *

        x = (int) touchPoint[0];
        y = (int) touchPoint[1];
sandy
  • 3,311
  • 4
  • 36
  • 47
0

In order to catch the coordinates of the touch, use the onTouch event of the imageView:

imageView.setOnTouchListener(this);

@Override
    public boolean onTouch(View view, MotionEvent me) {
        int x = me.getX();
        int y = me.getY();
        yourbitmap.setPixel(x + dx, y + dy, COLOR.RED);

        return true;

}

where dx, dy is the displacement of the bitmap in the imageView.

edit

The values of dx and dy depend on your settings of the imageview, which you have set yourself. If the bitmap is always centered and not screen-filling, dy= (imageview_height - bitmap_height) / 2 and dx= (imageview_width - bitmap_width) / 2. If the image is scaled to fit in the imageview, you have to determine the scale factor. You can read about those computations here.

Community
  • 1
  • 1
Ben Ruijl
  • 4,973
  • 3
  • 31
  • 44
  • Ben Ruijl thanks for your quick response. But I don't know how to get the "dx" and "dy" the displacement of the bitmap in the imageView please help thanks – jayangaVliyanage Sep 08 '12 at 17:13