Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to crop a rectangle from an image in android

Tags:

android

i'm using this example to crop an image that was selected from the gallery but the problem is that example only crop squares. Would it be possible to crop rectangles instead of only squares? In that example if I move one side the adjacent side moves along, keeping it a square selection.

Thanks.

like image 495
PauloBueno Avatar asked Feb 14 '12 19:02

PauloBueno


2 Answers

i found that's possible to crop rectangles using the built-in Android cropping handler.(com.android.camera.action.CROP). To crop rectangles you need to remove the following parameters of the example that i passed before:

intent.putExtra("outputX", 200); //Set this to define the max size of the output bitmap
intent.putExtra("outputY", 200); //Set this to define the max size of the output bitmap
intent.putExtra("aspectX", 1); //Set this to define the X aspect ratio of the shape
intent.putExtra("aspectY", 1); //Set this to define the Y aspect ratio of the shape

Setting the aspectX and aspectY will force the android to move both sides of the shape when you move one of them. Comment those lines and you'll be free to move the shape.

like image 175
PauloBueno Avatar answered Dec 04 '22 20:12

PauloBueno


Cropping to anything other than a square shape is not possible using the built-in Android cropping handling (com.android.camera.action.CROP).

You'd have to build your own cropping activity from scratch. You might want to base your own implementation on the implementation from the SDK (requires GIT).

Discussing that complex task into detail is out of scope for a simple answer on a Q&A site like Stack Overflow. If you have particular questions, don't hesitate to post another question.

like image 31
Paul-Jan Avatar answered Dec 04 '22 19:12

Paul-Jan