Nikki
Nikki

Reputation: 3318

How do I crop an image whose URI is known in Android?

I want image being shown in imageview to be selected with particular portion(and only selected portion needs to highlighted and other portion to be semi transparent) and that portion can also be resized as needed or done done by user on touch event.

Now, the selected portion of image is needed to be croped and then show and save that cropped image.

EDIT:

I used Intent to open the image and crop it using intent.putExtra("crop","true");

But while passing intent I want to open image whose URI is already known instead of opening the whole album of image gallery.

Can anyone suggest, how can I open particular URI through intent passing for opening image. Thanks in advance.

Upvotes: 4

Views: 3726

Answers (3)

Zelimir
Zelimir

Reputation: 11028

UPDATE: Changed my answer after question was edited and more precisely described.

Issue you are facing with has long history, also at SO:

unable to find com.android.camera.CropImage activity in android

One answer has described what you need. Please note that you are using intent that is not part of the official SDK, and you may encounter different kind of issues. Issue I experienced was using crop immediatelly after image was taken by the camera. Also, it is not compatible through different Android versions, so if you get it working for 1.5 maybe it will not work for 2.3. Other useful links:

http://groups.google.com/group/android-developers/browse_thread/thread/2dd647523926192c/569f36b5b28f2661?lnk=gst&q=Crop+image+intent#569f36b5b28f2661

http://groups.google.com/group/android-developers/browse_thread/thread/2dd647523926192c/dcbe5aef29eddad6?lnk=gst&q=Crop+image+intent#dcbe5aef29eddad6

http://groups.google.com/group/android-developers/browse_thread/thread/d7b6a133c164aa17/184bf3b85da2ce58?lnk=gst&q=Crop+image+intent#184bf3b85da2ce58

Upvotes: 2

Josh
Josh

Reputation: 10738

Check out my answer to this question. It doesn't deal with the touch-to-resize aspect of your question, but handles drawing parts of an image over the original image.

Bottom line is, you don't want to use an ImageView, since that's mainly for displaying a static image with various scaling properties. You're better off using a custom view with an overridden draw() method.

Upvotes: 1

Reuben Scratton
Reuben Scratton

Reputation: 38707

Regarding the last part of your question, if you're on the very latest Gingerbread (2.3.3, API level 10), you can use BitmapRegionDecoder to crop an image.

It's useful because, until this API existed, you had to load the entire image into memory before you could crop. With 5mpix and 8mpix cameras this is usually impossible without subsampling (i.e. the cropped image loses lots of resolution).

Upvotes: 3

Related Questions