Is there an Image cropping Activity in Android? I know that when you save an images as your wallpaper, it pops up an image cropper... and I've looked into the sourcecode for that, but it depends on a LOT of gallery specific stuff. Not very reusable.

Does anyone know how this might be done, or are there any third party libraries that can help me out on this one?

2 Answers
2

There's a reasonably well-supported Intent for this (worked on my testing on at least a half dozen different Android 2.1+ phones, including SenseUI and Motoblur devices, and I believe it's been around since Android 1.0 or earlier on the G1). This might get you started:

Then just handle what you need to do in the onActivityResult() method of your Activity; your output file should have the cropped image in it at that point.

NOTE: This code makes use of an internal API and will not work on all devices. To be safe, though, you may want to have a fallback behavior (autocrop? Don't crop?) if someone has a device that doesn't support this Intent.

How can I tell if this Intent is supported?
–
synicOct 22 '10 at 21:05

Also, are you sure that's the intent name? I get the following error on the Droid and the emulator: No Activity found to handle Intent { act=com.android.camera.action.CROP dat=file:///mnt/sdcard/data/okcupid/mediacache/takephoto (has extras) }
–
synicOct 22 '10 at 21:09

See this Romain Guy blog post on checking if there's an intent available: android-developers.blogspot.com/2009/01/… As far as why you're getting the error, it may not be recognizing the format of the URL you're passing it... I always operate directly on a URI returned in the data portion of an Intent from an ACTION_PICK or ACTION_IMAGE_CAPTURE, which I believe comes back with a "media://" URI. You also may want to check some other documentation, like androidworks.com/crop_large_photos_with_android
–
Yoni SamlanOct 24 '10 at 17:25

And of course, the Android AOSP source code for the Camera app, including its manifest, which should tell you exactly what intent-filters are set up for this on default Android devices.
–
Yoni SamlanOct 24 '10 at 17:25