hubert
hubert

Reputation: 21

Android I want to crop a image in size 500*500,It works on all device but samsung

As title, I want to crop a image which size is 500*500, It works on most device(like htc,sonyerrison,motors..),but samsung(Sii/Ace...).

Actually, Samsung Device can work on 360*360,but when I resize to 500*500.

The Behavior is quite weird, when I put

 intent.putExtra("outputX", 500);
 intent.putExtra("outputY", 360);
 startActivityForResult(intent,PHOTORESOULT),

It nerver comes back to onActivityResult()

Here is the cropping code,and I am sure that there is a image in that uri

    public void startPhotoZoom(Uri uri) {

             Bitmap bitmap =null;
    try {
        bitmap = MediaStore.Images.Media.getBitmap(
                this.getContentResolver(), uri);
        Log.v("cropImage","Heigh="+bitmap.getHeight()+" Width="+bitmap.getWidth());
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    int width=bitmap.getWidth();
    int height=bitmap.getHeight();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, IMAGE_UNSPECIFIED);
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    if(width < 500 || height < 500){
        if(width <= height){
            intent.putExtra("outputX", width); 
            intent.putExtra("outputY", width);
            Log.v("cropImage","outputX="+width+" outputY="+width);
        }else{
            intent.putExtra("outputX", height); 
            intent.putExtra("outputY", height);
            Log.v("cropImage","outputX="+height+" outputY="+height);
        }
    }else{
        intent.putExtra("outputX", 360);
        intent.putExtra("outputY", 360);
    }

    intent.putExtra("noFaceDetection", true);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, PHOTORESOULT);
}

I am struggling for a while~ Please Help~

Upvotes: 2

Views: 6319

Answers (2)

Arun Kumar
Arun Kumar

Reputation: 100

You can change like this,and you will get the exact cropped image from onActivityResult()

intent.putExtra("return-data", false);

Upvotes: -1

user1576140
user1576140

Reputation: 61

I assume, the cropped image is simply too big. To be relly sure you should read logcat.

I had the same Problem, that too large Image wouldnt be passed to onActivityResult and had to let the cropped image be saved to disk an then load it seperately.

simply omit

 intent.putExtra("return-data", true);

and set

 Uri destination;
 // some code to retriev an valid Uri
 intent.putExtra(MediaStore.EXTRA_OUTPUT, destination);

instead. Be sure that the Uri destination points to a file.

Upvotes: 6

Related Questions