I have an Activity containing an ImageView and I’d like to allow the User to select part of it’s content with the touch (or mouse click) capabilities.
I’d like to write a procedure able to achieve two things:
- Draw a highlighted window over the selected parts of the image
- Return an object containing the coordinates of the selected (highlighted) pixels.
For better understanding you can check the little mock up I’ve created:
The User should touch the screen over some part of the image and it should get highlighted. When pressing the back button I’d like to obtain via Java the coordinates of the pixels that were highlighted.
Can you help me understand how to do?
In particular I’d like to find out the following:
- should I access pixel level information of the image?
- which classes are needed to implement this functionality?
- some idea of pseudo code?
Thks for any kind of help!
I would subclass
ImageViewthen you can capture the touch events by overridingonTouchEvent(...)When you get to the
onDraw(...)method you can call super to draw the image as normal, then add your own code to draw a highlight over the top.EDIT
Well instead of using
ImageViewyou can extend it and write your own class, all this class has to do is overrideonTouchEvent(...)so you know when the view is being touched and can save the location on screen of the touch events. Next you edit the drawing methods: