0

I am currently doing a fault reporting page whereby the end user is able to report an image either by capturing using the camera or selecting a photo from the gallery. I am not sure why but when the image is taken using the camera, the height and width returned is about 220 by 180 which is a very blur image. I have tried looking online for other tutorials but my code seems to be the same as the others. Not too sure if it is my phone or what.

My code for Camera Intent:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);

My code after Capturing image from Camera:

thumbnail = (Bitmap) data.getExtras().get("data");
bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

ivImage.setVisibility(View.VISIBLE);
ivImage.setImageBitmap(thumbnail);

I've tried getting the width and height before and after compression, both returns the same value.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
user3567749
  • 13
  • 2
  • 8

1 Answers1

0

May be you should not compress the image rather simply use BitmapFactory.decodeFile(filePath) or any suitable method for getting your image from file into a bitmap (if not done already) and then set the bitmap object to the ImageResource like this:

Bitmap bitmap = BitmapFactory.decodeFile(filePath);
mImageView.setImageBitmap(bitmap);

And don't simply type cast the data received from intent. As far as I know about camera activity class, it will return a URI of the captured image. Try to receive it in onActivityResult() like this:

   @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK) return;

        if (requestCode == REQUEST_CAMERA) {
            Uri photoUri = data.getData();
            // Calculate the bitmap here according to the width of the device
            ((ImageView) findViewById(R.id.captured_image)).setImageBitmap(bitmap);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
Ashutosh Tiwari
  • 424
  • 3
  • 13