0

after using the below code for coping the image, the quality is really bad, so i'm asking if is there any solution to do something like instagram's croping utility, of if is there any coping library we can use here is my code :

  Intent intent = new Intent();
             // call android default gallery
             intent.setType("image/*");
             intent.setAction(Intent.ACTION_GET_CONTENT);
             // ******** code for crop image
             intent.putExtra("crop", "true");
             intent.putExtra("aspectX", 4);
             intent.putExtra("aspectY", 4);
             intent.putExtra("outputX", 800);
             intent.putExtra("outputY", 800);
             intent.putExtra("scale", true);
             intent.putExtra("scaleUpIfNeeded", true);
             intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());

             try {

             intent.putExtra("return-data", true);
             startActivityForResult(Intent.createChooser(intent,
             "Complete action using"), PICK_FROM_GALLERY);

             } catch (ActivityNotFoundException e) {
             // Do nothing for now
             }
          return true;
      case android.R.id.home:
           this.finish();
            return true;
      default:
          return super.onOptionsItemSelected(item);
  }
}

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


if (resultCode == RESULT_OK) {
    if (requestCode == PICK_FROM_GALLERY) {
Bundle extras2 = data.getExtras();


 if (extras2 != null)
 {



Bitmap photo = extras2.getParcelable("data");

attachimage.setImageBitmap(photo);
    Bitmap photo = extras2.getParcelable("data");
}

Here is the looking picture after coping : enter image description here

Nadador Base
  • 99
  • 10

1 Answers1

2

What you receive in the bundle is just a preview image (probably with some very strict size limit, because it is transfered across processes). Check how to retrieve the real result. Take a look at second anwser under this link: How to crop an image in android?

especially lines:

// true to return a Bitmap, false to directly save the cropped iamge
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
Community
  • 1
  • 1
Patman
  • 185
  • 1
  • 13