4
votes

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.

4
All mentioned image operations you may achieve using Canvas and Bitmap class. See for example stackoverflow.com/questions/4688306/…. To make some parts of the image semitransparent use XFer methods from android.graphics. - Zelimir
@Zelimir: Thanks but I have already seen that question but it doesn't contain about cropping the image in imageview. Can you please let me know about cropping the image - Nikki
@Nikki: So, what you need is to take some image, crop part of it (and save it), and make the rest semi transparent? - Zelimir
@Zelimir: yes......right, i need to do this, as you explained right now - Nikki
@Nikki: Easiest way is to use Bitmap android.graphics.Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height) and create new one from that. For partial transparency use XFer mode functions. - Zelimir

4 Answers

2
votes

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

3
votes

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).

1
votes

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.

0
votes

For Cropping image

private void cropImage() {
    // Use existing crop activity.
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(capturedImageUri, IMAGE_UNSPECIFIED);

    // Specify image size
    intent.putExtra("outputX", IMAGE_DIMENSION);
    intent.putExtra("outputY", IMAGE_DIMENSION);

    // Specify aspect ratio, 1:1
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    // REQUEST_CODE_CROP_PHOTO is an integer tag you defined to
    // identify the activity in onActivityResult() when it returns
    startActivityForResult(intent, REQ_CODE_CROP_PHOTO);
}