Nagendra
Nagendra

Reputation: 193

How do you make a resizable rectangle for cropping images in android?

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.

Screenshot

Upvotes: 4

Views: 4627

Answers (1)

senola
senola

Reputation: 782

As your question is very vague here is some general approach to solve this by creating an own View. I would suggest you extend the Androids ImageView with your own class.

Within this class you can use the

public void draw(Canvas canvas)

method to draw additional elements like a rectangular or circles for the corners (don't forget to call super.draw so that the image is also drawn.

Furthermore, you have to intercept the UI events on that view to decide if a corner was moved by the user. See http://developer.android.com/guide/topics/ui/ui-events.html for more details on that.

Within your layout you can add this view just by an XML tag with your package and view class as tag name. e.g.:

<com.example.MyCustomView android:layout_height="fill_parent" android:layout_width="fill_parent" android:src="@drawable/myImage"/>

Upvotes: 1

Related Questions