Low picture/image quality when capture from camera

Solution 1:

I have used the following code and this works perfectly fine for me.

            values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, "New Picture");
            values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
            imageUri = getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, PICTURE_RESULT);

and also

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

        case PICTURE_RESULT:
            if (requestCode == PICTURE_RESULT)
                if (resultCode == Activity.RESULT_OK) {
                    try {
                        thumbnail = MediaStore.Images.Media.getBitmap(
                                getContentResolver(), imageUri);
                        imgView.setImageBitmap(thumbnail);
                        imageurl = getRealPathFromURI(imageUri);    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
        }
    }

and

public String getRealPathFromURI(Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

Solution 2:

I will give you something that work for me. I asked the same !

Solution to save a picture in a specific folder without lost quality

I FOUND THE SOLUTION:

//Create a new folder code:

 String path = String.valueOf(Environment.getExternalStorageDirectory()) + "/your_name_folder";
            try {
                File ruta_sd = new File(path);
                File folder = new File(ruta_sd.getAbsolutePath(), nameFol);
                boolean success = true;
                if (!folder.exists()) {
                    success = folder.mkdir();
                }
                if (success) {
                    Toast.makeText(MainActivity.this, "Carpeta Creada...", Toast.LENGTH_SHORT).show();
                }
            } catch (Exception ex) {
                Log.e("Carpetas", "Error al crear Carpeta a tarjeta SD");
            }

            Intent i = new Intent(MainActivity.this, MainActivity.class);
            startActivity(i);
            finish();//agregue este

//Method to take a Picture

public void clickFoto(View view) {
        takePic();
    }

//takePic()

 private void takePic() {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        *File file = new File(Environment.getExternalStorageDirectory(), "/your_name_folder/a" + "/photo_" + timeStamp + ".png");*
        imageUri = Uri.fromFile(file);

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, PICTURE_RESULT);
    }

//onActivityResult

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {

            case PICTURE_RESULT:
                if (requestCode == PICTURE_RESULT)
                    if (resultCode == Activity.RESULT_OK) {
                        try {
                            Bitmap thumbnail = MediaStore.Images.Media.getBitmap(
                                    getContentResolver(), imageUri);
                            imgFoto.setImageBitmap(thumbnail);
                            imageurl = getRealPathFromURI(imageUri);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
        }
    }

// getRealPathFromUri

public String getRealPathFromURI(Uri contentUri) {
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }