Search code examples
androidresize-crop

How to open Image directly with crop option


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


Solution

  • 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);