Search code examples
androidandroid-imageviewandroid-canvas

Android: Draw a moveable and sizeable rectangle on ImageView(Or any other bitmap compatible widget) and crop the selected region


I want to crop my image which is being displayed on an ImageView. How I want to go about it is that I want a re-sizable rectangle to be displayed on the image. That rectangle will have moveable corners (which I can drag around with touch) to increase/decrease its size. The image below illustrates a demo of something I would like to develop.

P. S. I am not quite sure how to phrase my question. What I want: http://imageshack.us/photo/my-images/832/customcropbox.jpg/


Solution

  • The final solution I came up with after ample research was:

    Extend ImageView to make my own custom view.

    @Override onDraw method and do my custom drawing there in that method.

    Implement onTouchListener on the view to get the touch events and process them according to their position.

    e. g.

    I checked whether the touch was in the radius of the anchor point circle I drew around the movable rectangle that I was drawing in my overriden onDraw method.

    Edit: I am sorry guys I don't have that piece of code anymore, I came here after a very long time otherwise would have loved to help you out.

    Heartache.