0

I want to crop an image , I am able to implement this.

My code is as

Intent cropIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);         
        cropIntent.setDataAndType(fileUri, "image/*");
        // set crop properties
        cropIntent.putExtra("crop", "true");    
        cropIntent.putExtra("return-data", true);       
        startActivityForResult(cropIntent, CROP_PIC);

where fileUri contains URI for path of image which I want to crop from Gallery.

Using this code an alert opens to choose application to select image, I am wondering while I have passed Image path already then why its asking to select application to open Image and when I select application(via Gallery) then I have to choose image from Gallery to crop.

I want a solution using which my image just opens up with crop option without asking to select application to open with ?

Is it possible? please help me to achieve it...

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
  • There's almost no chance unless you are using the content viewer instead. Checkout [this post](http://stackoverflow.com/questions/5383797/open-an-image-using-uri-in-androids-default-gallery-image-viwer). – Matthias Jul 20 '15 at 06:17
  • @androidcode did you find the solution? – Amy Jul 20 '15 at 06:52

2 Answers2

1

Try With This:

     String filename = "image.png";
     String path = "/mnt/sdcard/" + filename;
     File f = new File(path);  //  
     Uri imgUri= Uri.fromFile(f);  
     Intent intent = new Intent("com.android.camera.action.CROP");  
            intent.setDataAndType(imgUri, "image/*");  
            intent.putExtra("crop", "true");  
            intent.putExtra("aspectX", 1);  
            intent.putExtra("aspectY", 1);  
            intent.putExtra("outputX", 50);  
            intent.putExtra("outputY", 50);  
            intent.putExtra("return-data", true);
            startActivityForResult(intent, 1);
Amy
  • 4,034
  • 1
  • 20
  • 34
0

Using the native crop is not good solution, because the behavior of each crop is different. I came across some errors as it is not possible to save a file, is not correct aspect ratio, maybe there are also other.
I think the best solution to use custom crop library after pick photo from gallery.
There are some good libraries with examples like https://github.com/jdamcd/android-crop or https://github.com/lvillani/android-cropimage or https://github.com/edmodo/cropper

Dmitriy Puchkov
  • 1,530
  • 17
  • 41