-1

I am creating a app in which on button click i open the default camera to camera a image and save that image.But when ever i am viewing that image,the quality of that image is very poor.I dont know why this is happening???

Code

if (userSelection.contains("Camera")) {
                            intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            startActivityForResult(intent, 1);
                            btChooseDoc.setText("Choose File");
                        }




    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);{
    Bitmap camera;
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();

        if (requestCode == 1 && resultCode == getActivity().RESULT_OK) {

            camera = (Bitmap) data.getExtras().get("data");

            Uri tempUri = getImageUri(getActivity(), camera);
            strFilePath = getPath(getActivity(), tempUri);
            file = new File(strFilePath);
            camera.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//            camera = Bitmap.createScaledBitmap(camera, 150, 150, false);
            image.setImageBitmap(camera);
            date = sdf.format(new Date());
}
Anuj
  • 402
  • 8
  • 16

1 Answers1

0

Change

galleryImage.compress(Bitmap.CompressFormat.JPEG, 60, bytes);

to

galleryImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

The second argument in the compress method is the quality of the image. If you give a small value it will decrease the image quality to compress it.

Apoorv
  • 13,470
  • 4
  • 27
  • 33