0

I'm in trouble with low quality of cropped image.

Here is my situation with simple code.

crop_image() method below.

    Intent crop = new Intent("com.android.camera.action.CROP");
    crop.setDataAndType(outputFileUri, "image/*");

    crop.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    crop.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

    crop.putExtra("crop", "true");
    crop.putExtra("aspectX", 139);
    crop.putExtra("aspectY", 185);
    crop.putExtra("scale", true);

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

    startActivityForResult(crop, CROP_AFTER_CAMERA);

After cropping image from camera, set ImageView

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_FROM_CAMERA && resultCode == RESULT_OK) {
        if (outputFileUri != null) {
            crop_image();
        }
    }

    else if (requestCode == EDIT_CROPPED_IMAGE) {

    }

    else if (requestCode == CROP_AFTER_CAMERA) {


        if (data != null) {
            Bundle bundle = data.getExtras();
            Bitmap cropBit = bundle.getParcelable("data");

            imgView.setImageBitmap(cropBit);

            saveBitmap(cropBit);

        }
    }

    else if (resultCode == RESULT_CANCELED) {
        Provider.deleteFile(getBaseContext(), outputFileUri);
    }
}

After that, I stored bitmap image using compress method.

    OutputStream out = null;

    File image_file = new File(targetFolder + filename);

    try {
        image_file.createNewFile();
        out = new FileOutputStream(image_file);

        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            out.close();
        }
    }

The result of both bitmap image(stored bitmap image and on the ImageView) have

low quality.

How can I recover image's quality?

Thanks for helping me!!

Na Jun Yeop
  • 55
  • 1
  • 7

0 Answers0