TheLettuceMaster
TheLettuceMaster

Reputation: 15734

Take Picture with Camera then Crop

I want to be able to take a picture with the the camera. I do it this way and it works:

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
 startActivityForResult(intent, CAMERA_REQUEST);

After this is successful, I want user to be able to IMMEDIATELY view image and be able to crop.

I can do that like this:

        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(Uri.fromFile(new File(file.toString())), "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, CAMERA_REQUEST);

How do I merge these two tasks so they happen one after the other? Do I have to have TWO startActivityForResult? Should it be merged? Or should the croppin ginfo be inside the normal?

    getActivity();
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {


                    // Cropping code here? another intent?

        iPP.setImageBitmap(BitmapFactory.decodeFile(file.toString()));
        imagePath = file.toString();
        scaleImage();
        new UploadImage().execute();
    }

Upvotes: 2

Views: 2339

Answers (1)

dannyroa
dannyroa

Reputation: 5571

Create a new constant called CAMERA_CROP.

When you start the activity after taking a photo, send the CAMERA_CROP request code.

if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
    ...
    startActivityForResult(cropIntent, CAMERA_CROP);
}

When you return from the Crop Activity, handle the request code.

if (requestCode == CAMERA_CROP && resultCode == Activity.RESULT_OK) {
...
}

Upvotes: 1

Related Questions