2

Actually now i'm going on with my crop section for that I need to crop my image on all four sides height and width but I can't select my height I had went with this tutorial.

http://www.coderzheaven.com/2012/12/15/crop-image-android/

enter image description here

What I need was exactly like the above image to adjust on all sides.

Can any one help me to fix this problem.

ligi
  • 39,001
  • 44
  • 144
  • 244
user3737339
  • 231
  • 1
  • 5
  • 11
  • The best library I found to crop images was [Android-Image-Cropper](https://github.com/ArthurHub/Android-Image-Cropper). See this [answer](https://stackoverflow.com/a/51985041/8383332). – Soon Santos Aug 23 '18 at 11:45

5 Answers5

2

You can try using this Cropper Library

Its a great image cropping library. I have used it mostly in my apps. Here is a screenshot of the library in action:

enter image description here

I hope you can find it useful. Cheers! :)

icaneatclouds
  • 1,170
  • 9
  • 18
2

Intent com.android.camera.action.CROP is not a standard android intent and there are many devices that donot support this intent. Please refer to my answer in this SO post. I am using a library from github to do the cropping.

Community
  • 1
  • 1
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
1

you can use this function

private void doCrop(Uri mImageCaptureUri) {

    this.mImageCaptureUri = mImageCaptureUri;
    Intent intent = new Intent("com.android.camera.action.CROP");
    // intent.setType("image/*");
    intent.setDataAndType(mImageCaptureUri, "image/*");
    List<ResolveInfo> list = getPackageManager().queryIntentActivities(
            intent, 0);
    int size = list.size();

    if (size == 0) {
        // Toast.makeText(this,
        // "Can not find image crop section",Toast.LENGTH_SHORT).show();
        return;
    } else {
        // Toast.makeText(this,
        // "image crop section started..",Toast.LENGTH_SHORT).show();

        intent.setData(mImageCaptureUri);

        // Bitmap bitmap_1 = readBitmap(mImageCaptureUri);
        try {
            bitmap = MediaStore.Images.Media.getBitmap(
                    this.getContentResolver(), mImageCaptureUri);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }// = bitmap_1;
        new MydataLoader().execute(function.sendimage);
        // changed
        intent.putExtra("outputX", 200);
        intent.putExtra("outputY", 200);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        // Log.e("size",""+size);
        if (size >= 1) {
            // Toast.makeText(MerchantLogin.this,
            // "Cropimage got called with size"+ size,
            // Toast.LENGTH_SHORT).show();
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent(new ComponentName(res.activityInfo.packageName,
                    res.activityInfo.name));

            startActivityForResult(i, CROP_FROM_CAMERA);

        } else {
            // Toast.makeText(MerchantLogin.this,
            // "Cropimage not get called", Toast.LENGTH_SHORT).show();
        }

    }
}

To call crop action of camera used intent "com.android.camera.action.CROP"

Minp
  • 98
  • 1
  • 1
  • 13
0

If you can use a third party library

https://github.com/jdamcd/android-crop https://github.com/edmodo/cropper

Veeru
  • 4,936
  • 2
  • 43
  • 61
0

Try this library:

https://github.com/biokys/cropimage

For a square:

intent.putExtra(CropImage.ASPECT_X, 2);
intent.putExtra(CropImage.ASPECT_Y, 2);

For a rectangle:

intent.putExtra(CropImage.ASPECT_X, 3);
intent.putExtra(CropImage.ASPECT_Y, 2);
Rajesh Mikkilineni
  • 854
  • 10
  • 22