Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:08:05+00:00 2026-06-14T14:08:05+00:00

I have an application where I can let the user choose a gallery image

  • 0

I have an application where I can let the user choose a gallery image or take a picture with camera, then after that I give him the option to crop it.

Now when the user crops the image the Gallery cropper returns ByteArray of the cropped part, is it possible to pass a parameter asking the Gallery cropper to save the output to file (Just like the case when I start a intent to capture and image in the camer)

e.g.:

This is the code of cropping that I Use:

// Initialize intent
Intent intent = new Intent("com.android.camera.action.CROP");
// set data type to be sent
intent.setType("image/*");

// get croppers available in the phone
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
// handle the case if there's no cropper in the phone
if (size == 0) {
    Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
    return;
} else {

// now this is the case if cropper exists
// initialize the Uri for the captures or gallery image

    Uri imageUri = Uri.fromFile(new File(mCurrentPhotoPath));

    // Send the Uri path to the cropper intent
    intent.setData(imageUri); 
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 200);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);         
    intent.putExtra("scale", true);
    // Here's my attempt to ask the intent to save output data as file
    File f = null;
    // Here I initialize empty file 
    try{
            // This returns the file created
        f = setUpCroppedFile();
        mCurrentThumbPath = f.getAbsolutePath();            
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));            
        intent.putExtra("output", Uri.fromFile(f));         
    }
    catch(IOException e){
        e.printStackTrace();
    }
    // --------------------------------------------------------------------
    // -----------> When changing this to false it worked <----------------
    // --------------------------------------------------------------------        
    intent.putExtra("return-data", true);
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------

    // If there's only 1 Cropper in the phone (e.g. Gallery )
    if (size == 1) {
            // get the cropper intent found
            Intent i        = new Intent(intent);
            ResolveInfo res = list.get(0);

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

            startActivityForResult(i, CROPPED_PHOTO);
    }

   // Please ignore the case if there are more . . I know how to handle it 

Update: the issue is fixed, I see I’d leave this here as is in case someone else find it useful ( See the big comment inside the code above )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:08:06+00:00Added an answer on June 14, 2026 at 2:08 pm

    This code is the modified one and it works:

    // Initialize intent
    Intent intent = new Intent("com.android.camera.action.CROP");
    // set data type to be sent
    intent.setType("image/*");
    
    // get croppers available in the phone
    List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
    int size = list.size();
    // handle the case if there's no cropper in the phone
    if (size == 0) {
        Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
        return;
    } else {
    
    // now this is the case if cropper exists
    // initialize the Uri for the captures or gallery image
    
        Uri imageUri = Uri.fromFile(new File(mCurrentPhotoPath));
    
        // Send the Uri path to the cropper intent
        intent.setData(imageUri); 
        intent.putExtra("outputX", 200);
        intent.putExtra("outputY", 200);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);         
        intent.putExtra("scale", true);
        // Here's my attempt to ask the intent to save output data as file
        File f = null;
        // Here I initialize empty file 
        try{
                // This returns the file created
            f = setUpCroppedFile();
            mCurrentThumbPath = f.getAbsolutePath();            
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));            
            intent.putExtra("output", Uri.fromFile(f));         
        }
        catch(IOException e){
            e.printStackTrace();
        }
        // --------------------------------------------------------------------
        // -----------> When changing this to false it worked <----------------
        // --------------------------------------------------------------------        
        intent.putExtra("return-data", false);
        // --------------------------------------------------------------------
        // --------------------------------------------------------------------
    
        // If there's only 1 Cropper in the phone (e.g. Gallery )
        if (size == 1) {
                // get the cropper intent found
                Intent i        = new Intent(intent);
                ResolveInfo res = list.get(0);
    
                i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
    
                startActivityForResult(i, CROPPED_PHOTO);
        }
    
       // Please ignore the case if there are more . . I know how to handle it 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some option-item combination in my application from which the user can choose
I have an application (winforms) that downloads a file to user's temporary folder, then
I'm planning to make an application that can let the user accessing the Internet
I have an application that can filter a datagridview based on date using a
I have an application that can be viewed with landscape and portrait mode. I'm
I have an application that can potentially have hundreds of memory mapped, i.e., mmap()
I have an application where I can have an image moving towards the eye.
I have a web application that can load plugins through reflection. It currently uses
I want to let application user know that whom buddy has downloaded the application
I have a web application that I'll be distributing to customers. I'll give them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.