Search code examples
androidcrop

change the ration of android crop functionality


I am using the crop functionality of android. My problem is everytime I drag the left/right side of the square, the bottom follows. It retains the ratio of the square shape.

Any solutions how to change the ratio of the box, for example I want to crop a rectangular shape instead of square shape.

This is my code

 private void doCrop() {
    try {
            Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
            cropIntent.setDataAndType(mImageCaptureUri, "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, CROP_FROM_CAMERA);  
    }
    catch(ActivityNotFoundException anfe)
    {
        String errorMessage = "your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
   if(requestCode == CROP_FROM_CAMERA && resultCode == RESULT_OK)
    {
        Bundle extras = data.getExtras();
        Bitmap thePic = extras.getParcelable("data");
        ImageView picView = (ImageView)findViewById(R.id.imgView);
        picView.setScaleType(ScaleType.FIT_XY);
        picView.setImageBitmap(thePic);
    }
}

Solution

  • I found simple solution for this:

    intent.putExtra("aspectX", 0);
    intent.putExtra("aspectY", 0);