Image being saved with poor quality

Asked

Viewed 32 times

-1

The following code is to save the image in a certain folder, which is taken by my application, but the image is saved with a horrible quality, even being at most "100".

        if (requestCode == 5) {
        if (resultCode == RESULT_OK) {
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            try {
                EditText nome = (EditText) findViewById(R.id.editTextScan);
                String nome2 = String.valueOf(nome.getText());
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);


                byte[] bytes = stream.toByteArray();
                File arq  = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "/Pasta/Qualidade/" + nome2+".png");

                FileOutputStream fos = new FileOutputStream(arq);
                fos.write(bytes);
                fos.close();
                Toast.makeText(getApplicationContext(), "Salvou foto", Toast.LENGTH_LONG).show();

            } catch (Exception e) {
                e.printStackTrace();
            }

        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Foto cancelada.", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "Cancelamento automático.", Toast.LENGTH_SHORT).show();
        }

    }

1 answer

0

Some formats like PNG ignore the quality setting.

Already tried with another image format?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.