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

  • SEARCH
  • Home
  • 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 9157519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:02:20+00:00 2026-06-17T13:02:20+00:00

I’m trying to use a method to crop a image. Exactly this method: private

  • 0

I’m trying to use a method to crop a image. Exactly this method:

private void performCrop() {
    try {
        //call the standard crop action intent (the user device may not support it)
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri
        cropIntent.setDataAndType(**HERE**, "image/*");
        //set crop properties
        cropIntent.putExtra("crop", "true");
        //indicate aspect of desired crop
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        //indicate output X and Y
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        //retrieve data on return
        cropIntent.putExtra("return-data", true);
        //start the activity - we handle returning in onActivityResult
        startActivityForResult(cropIntent, 1234);
    }
    catch(ActivityNotFoundException anfe){
        Log.d("debugging","EXCEPTION");/*
        //display an error message
        String errorMessage = "Whoops - your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();*/
    }
}

This line, asks for a Uri Data and String Type.

    cropIntent.setDataAndType(**HERE**, "image/*");

But I just want to put this bitmap

Bitmap fotoCreada;

as Data, but I don’t know how to do it.

Is there any way to achieve this?

Thanks.

EDIT

Okay, this is my code right now:

There’s a button. When you click it:

public void onClick(View v) {
            Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
            if(isSDPresent) {
                //Creem carpeta
                File folder = new File(Environment.getExternalStorageDirectory().toString()+"/pic/");
                folder.mkdirs();
                //Recuperem data actual
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
                String currentDateandTime = sdf.format(new Date());
                //Cridem a la camara.
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                resultingFile=new File(folder.toString() + "/"+currentDateandTime+".jpg");
                Uri uriSavedImage=Uri.fromFile(resultingFile);
                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                //Començem activity
                startActivityForResult(cameraIntent, 1888); 
            } else {
                Toast toast = Toast.makeText(getActivity(), "Issues while accessing sdcard.", Toast.LENGTH_SHORT);
                toast.show();
            }
        }   

As you can see, it’s calling startActivityForResult. Basically takes a picture, and I retrieve it on activityResult:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("debugging",""+resultCode);
    if( requestCode == 1888 && resultCode == -1) { //-1 = TOT HA ANAT BE.
        Bitmap photo = BitmapFactory.decodeFile(resultingFile.getPath());
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        Bitmap photoRotated = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
        this.fotoCreada=photoRotated;
        ((ImageView) myFragmentView.findViewById(R.id.fotoCapturada)).setImageBitmap(this.fotoCreada);
        try {
            FileOutputStream out = new FileOutputStream(this.resultingFile.getPath());
            this.fotoCreada.compress(Bitmap.CompressFormat.PNG, 90, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        performCrop();
    }
    if (requestCode == 1234 && resultCode == -1){
        Bitmap bitmap = (Bitmap) data.getParcelableExtra("BitmapImage");
        Log.d("debugging",""+bitmap.getHeight());
    }
}

And as you can see from previous code, as I retrieve the bitmap, I call method performCrop. It’s code, now, is:

private void performCrop() {
    try {
        //call the standard crop action intent (the user device may not support it)
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri
        //cropIntent.setDataAndType(this.picUri, "image/*");
        cropIntent.putExtra("BitmapImage", this.fotoCreada);
        //set crop properties
        cropIntent.putExtra("crop", "true");
        //indicate aspect of desired crop
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        //indicate output X and Y
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        //retrieve data on return
        cropIntent.putExtra("return-data", true);
        //start the activity - we handle returning in onActivityResult
        startActivityForResult(cropIntent, 1234);
        Log.d("debugging","he acabat performCrop");
    }
    catch(ActivityNotFoundException anfe){
        Log.d("debugging","EXCEPTION");
        //display an error message
        String errorMessage = "Whoops - your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}

But startActivityForResult from performCrop never ends up calling onActivityResult. Log cat says it just entered once, and should enter Twice. First one from the camera Activity and second from Crop activity.

-1
he acabat performCrop

Hope it’s clear enough.

Thanks.

  • 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-17T13:02:21+00:00Added an answer on June 17, 2026 at 1:02 pm

    Bitmap implements Parcelable, so you could always pass it in the intent:

    Intent intent = new Intent(this, NewActivity.class);
    intent.putExtra("BitmapImage", bitmap);
    

    and retrieve it on the other end:

    Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
    

    However, if the bitmap exists as a file or a resource, its is always better to pass the URI or ResourceID of the bitmap and not the bitmap itself. Passing the entire bitmap requires a lot of memory. Passing the URL requires very little memory and allows each activity to load and scale the bitmap as they need it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.