Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android image cropping is reducing the size of the image

I need to crop a photo from the android phone gallery and then edit it. The original size of the photo is 3264 *2448 which is displayed in my screen of size 1280 * 720 as a scaled down image. When I crop it, i am getting a image of size 185 * 139.

The code I am using for cropping is

        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(picUri, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, PIC_CROP);

When I display the cropped image in an imageView it is displayed as a much smaller image.

I should be cropping the original sized image and not the scaled down version. Could any of you please guide me as to how to do this?

like image 629
namrathu1 Avatar asked Jan 17 '13 17:01

namrathu1


2 Answers

Please try this, i know its too late, but may help someone.

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(mImageCaptureUri, "image/*");
    //set crop properties
    cropIntent.putExtra("crop", "true");
    //indicate aspect of desired crop
    cropIntent.putExtra("aspectX", 4);
    cropIntent.putExtra("aspectY", 3);
    //indicate output X and Y
    cropIntent.putExtra("outputX", 800);
    cropIntent.putExtra("outputY", 800);

File f = new File(Environment.getExternalStorageDirectory(),
        "/temporary_holder.jpg");
    try {
        f.createNewFile();
    } catch (IOException ex) {
    Log.e("io", ex.getMessage());  
    }

uri = Uri.fromFile(f);

  cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

    startActivityForResult(cropIntent, PIC_CROP);

} //respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
    //display an error message
    String errorMessage = "Your device doesn't support the crop action!";
    Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
    toast.show();
}
}

Make your onActivityResult like this :-

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

     if (requestCode == PIC_CROP) {

              String filePath = Environment.getExternalStorageDirectory()
                    + "/temporary_holder.jpg";

            thumbnail = BitmapFactory.decodeFile(filePath);



                   //thumbnail =    BitmapFactory.decodeFile(filePath);
           //    Log.i("",String.valueOf(thumbnail.getHeight()));

                ImageView image = (ImageView) findViewById(R.id.pestImage);
                image.setImageBitmap(thumbnail);
                }
}
like image 186
Akanksha Rathore Avatar answered Nov 18 '22 04:11

Akanksha Rathore


Add:

intent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);

Then you can get an image file which is not reduced. And use this saved file instead of:

Intent.getExtras().getParcelable("data")

Just ignore returned bitmap.

like image 31
NaturalFlow Avatar answered Nov 18 '22 04:11

NaturalFlow