0

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

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
Tooti Tooti
  • 109
  • 7
  • Instead of passing `null` for `EXTRA_OUTPUT`, [use it to get a full-size image](https://developer.android.com/training/camera/photobasics#TaskPath), rather than a thumbnail. – CommonsWare Oct 13 '18 at 10:55
  • @CommonsWare Can you help me more ? – Tooti Tooti Oct 13 '18 at 11:16
  • I linked to documentation in my previous comment. [Here is a sample app](https://github.com/commonsguy/cw-omnibus/tree/v8.13/Camera/FileProvider) (covered in [this book](https://commonsware.com/Android)) that implements it, though it uses `ACTION_IMAGE_CAPTURE` rather than `ACTION_IMAGE_CAPTURE_SECURE`. – CommonsWare Oct 13 '18 at 11:18

1 Answers1

1

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

Stane
  • 26
  • 3
  • Thank you, where i use it ? – Tooti Tooti Oct 13 '18 at 11:16
  • try to modify your method like: `public Uri getImageUri(Bitmap inImage) { Bitmap bitmapScaled = Bitmap.createScaledBitmap(inImage, width, height, true); String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmapScaled, "Title", null); return Uri.parse(path); }` – Stane Oct 13 '18 at 20:36
  • not work for me – Tooti Tooti Oct 14 '18 at 08:23