Yeehoong Lim
Yeehoong Lim

Reputation: 41

How to display an image capture by camera with original size?

I am trying to implement an app that will use camera to capture an image and display it on the ImageView. However, the system will resize the pic resolution to 204x153 before it display on the screen, but it save the original resolution (3264x2448) of the image in sd card.

this is my code.

buttonCapture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent intentCamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            bmpUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),  
                    "pic_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));  
            try {  
                intentCamera.putExtra("return-data", false);  
                startActivityForResult(intentCamera, resultOpenCamera);  
            } 
            catch (ActivityNotFoundException e) {  
                e.printStackTrace();  
            }               
        }
    });

and my onActivityResult

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

        if (requestCode == resultOpenCamera && resultCode == RESULT_OK && null != data) {
            setContentView(R.layout.preview);

            if(data.getAction() != null){  

               Uri selectedImage = data.getData();
               bmpUri = selectedImage;
               // display image received on the view
               Bundle newBundle = data.getExtras();
               Bitmap theImage = (Bitmap) newBundle.get("data");
               displayImage(preProcessing(theImage));  
               System.out.println("theImage height n width = "+theImage.getHeight()+" + "+theImage.getWidth());
            }
        }
}

I have use System.out.println to trace the bitmap resolution that capture from the camera. it show that only have 204x153. The original resolution should be 3264x2448.

Anyone know how to solve this?? Thanks a lot.

Upvotes: 1

Views: 2914

Answers (3)

ArtemStorozhuk
ArtemStorozhuk

Reputation: 8725

Just from official documentation of ACTION_IMAGE_CAPTURE:

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

Upvotes: 2

Deepanker Chaudhary
Deepanker Chaudhary

Reputation: 1704

Try This :-

int width = bmpSelectedImage.getWidth();
int height = bmpSelectedImage.getHeight();
float scaleWidth = ((float) 250) / width;
float scaleHeight = ((float) 150) / height;
Matrix matrix = new Matrix(); matrix.postRotate(90);
resizedBitmap = Bitmap.createBitmap(bmpSelectedImage, 0, 0, width, height, matrix, true);

Upvotes: 0

RSai
RSai

Reputation: 51

Try to set the scale type of the imageview to center or centerInside.

Upvotes: 0

Related Questions