How can I crop a image? I have tried some concepts using intents but still failed.. I want this type of cropping.
-
Can you be more specific, please? – Andrei Verdes Nov 03 '15 at 10:38
-
i just want to crop image just like display above link.there are 8 point for cropping and i want to adjust cropping point from this 8 point.i use CropImageview library but unable to crop image. – Kishan patel Nov 03 '15 at 10:56
-
https://github.com/cesards/CropImageView here this was a link which library i can use . – Kishan patel Nov 03 '15 at 10:57
-
can you share the project? or some code? maybe something goes wrong... – Andrei Verdes Nov 03 '15 at 12:14
-
in simple i wann take a pic from camera n crop that image like you see in image how can i do that i use that library but that cant help me . – Kishan patel Nov 03 '15 at 12:26
3 Answers
1.Have an Activity with your CropImageView
in it's layout.
2.Start the camera activity with an Intent
with 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

- 993
- 8
- 23
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
-
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
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());

- 498
- 1
- 6
- 13