1

How can I crop a image? I have tried some concepts using intents but still failed.. I want this type of cropping.

Here's a image:

Cœur
  • 37,241
  • 25
  • 195
  • 267
Kishan patel
  • 214
  • 1
  • 12

3 Answers3

0

1.Have an Activity with your CropImageView in it's layout.
2.Start the camera activity with an Intentwith a startActivityForResult to take the picture.
3.In the Activity, override onActivityResult to take the picture bitmap and do `CropImageView.setImageBitmap(bitmap) and voila! Now you can crop it...
Have a look at this one for an example: Capture Image from Camera and Display in Activity

Andrei Verdes
  • 993
  • 8
  • 23
0

Try out following code:

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 1; 
Bitmap bm = BitmapFactory.decodeFile(imagePath, opts);
Intent intent = new Intent("com.android.camera.action.CROP");              
intent .setDataAndType(outputFileUri, "image/*");
intent.putExtra("outputX",bm.getWidth());
intent.putExtra("outputY", bm.getHeight());
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("scale", true);
intent.putExtra("return-data", false); 
startActivityForResult(intent, 2);

following parameters play vital role:

 intent.putExtra("aspectX", 0);
    intent.putExtra("aspectY", 0);

For more info: Android - Crop image taken from camera with resizable ,independant height and width of cropped area

Community
  • 1
  • 1
Umesh
  • 1,609
  • 1
  • 17
  • 28
  • this type of crop image i already done i want that type of cropping which i view in que. see that thank you for advice – Kishan patel Nov 04 '15 at 04:42
0

Have a xml file for your activity where you will display the original image in the main_imageview and add another imageview as child to the crop_main_layout having the crop rect image as src (9 patch image)

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/crop_main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/imageview_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center" >
        <ImageView
            android:id="@+id/main_imageview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/transparent"
            android:scaleType="centerInside"
            android:padding="@dimen/crop_view_padding"/>
    </LinearLayout>
</RelativeLayout>

The crop rect image view can be a custom class deriving from Imageview which will handle all onTouchEvents and will provide resize/move functionality and once user selects the selection and presses Done on your crop screen, crop the image using the selected crop rect (custom crop rect image view bounds).

Bitmap.createBitmap(currentBitmap, cropRect.left, cropRect.top, cropRect.width(), cropRect.height());
Shilpi
  • 498
  • 1
  • 6
  • 13