Search code examples
androidimageandroid-camera-intent

Image camera quality is bad


My code :

final Uri fileUri = null;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, 2);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Uri final = getImageUri((Bitmap) data.getExtras().get("data"));
        final String filePath = getPath(final);
    }
}

Get image uri :

public Uri getImageUri(Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

After this, my image is bad quality

How i can fix it ?

Thank you


Solution

  • This is happening because of compression. If you really need to compress it try to use:

    Bitmap bitmapScaled = Bitmap.createScaledBitmap(inImage, width, height, true);
    

    please also have a look here, maybe you can find something that will work better for you:

    https://developer.android.com/training/camera/photobasics#java