Im trying to capture an image from the camera, compress it, then store it to the SD card. If I directly save it to the SD card using the code directly below, I get the full image. But if i try and load the image in the system, i get a super small image size such as 320 by 240 instead of a full 5 mp image.
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri());
    startActivityForResult(intent, CAMERA_PIC_REQUEST);  
where getImageURI() is
    private Uri getImageUri() {
    // Store image in dcim
    file = new File(Environment.getExternalStorageDirectory() + "/DCIM","itshelp.jpg");
    imgUri = Uri.fromFile(file);
    file.deleteOnExit();
       Log.e("syS","file is at "+imgUri);
    return imgUri;
}
Now when i try to save it to internal memory instead, I use the following code that gets me the tiny image:
    public void imageFromCamera() { //code to retrieve image
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent, CAMERA_PIC_REQUEST);  
    }
and in my startActivitForResult I have the following:
    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
        Bitmap bm = (Bitmap) data.getExtras().get("data"); 
        Log.e("sys", "width is "+bm.getWidth()); //im gettting an extremely small width here
        OutputStream outStream = null;
        file = new File(Environment.getExternalStorageDirectory() + "/DCIM","itshelp.png");
        try {
         outStream = new FileOutputStream(file);
         bm.compress(Bitmap.CompressFormat.JPEG, 70, outStream);
         outStream.flush();
         outStream.close();
         Log.i("Hub", "OK, Image Saved to SD");
         Log.i("Hub", "height = "+ bm.getHeight() + ", width = " + bm.getWidth());
        } catch (FileNotFoundException e) {
         e.printStackTrace();
         Log.i("Hub", "FileNotFoundException: "+ e.toString());
        } catch (IOException e) {
         e.printStackTrace();
         Log.i("Hub", "IOException: "+ e.toString());
        }
    }
When you call the camera intent without MediaStore.EXTRA_OUTPUT, the camera returns only a small thumbnail since the intent bundle is not designed to pass large memory blocks.
From the SDK documentation for MediaStore:
Standard Intent action that can be sent to have the camera application capture an image and return it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With