开发者

android picture from camera being taken at a really small size

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"); 
    开发者_如何学Python    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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜