0

I am trying to have my app take a picture and return that picture for use. However, it is throwing an exception both in the emulator and on a Nexus One.

Here is my code:

private File temporaryCameraFile = new File("/sdcard/tmp.bmp");

When chose from the menu to take a picture:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(temporaryCameraFile));
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

in onActivityResult()

if(resultCode == RESULT_OK){
    Bitmap cameraPicture = decodeFile(temporaryCameraFile);

    // resize to fit screen and add to queue to be drawn
    if (cameraPicture != null)
        if ((cameraPicture.getWidth() > 0) && (cameraPicture.getHeight() > 0))
            page.SetBackground(ResizeImageToFit(cameraPicture));
}

decodeFile()

private Bitmap decodeFile(File f){
    try {
        //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //decode with inSampleSize
        o.inJustDecodeBounds = false;
        Bitmap retval = BitmapFactory.decodeStream(new FileInputStream(f), null, o);

        return retval;
    } catch (FileNotFoundException e) {
        Log.e("decodeFile()", e.toString());
        return null;
    }
}

In decodeFile(), the first decode properly returns the bounds. However, when I call it the second time, I get the following error on both the emulator and the Nexus One. I tried updating the decodeFile to only do the main decode without the inJustDecodeBounds method, but that failed as well. Also, I have pulled the file off of the device manually and it is a valid bitmap.

  09-20 15:30:58.711: ERROR/AndroidRuntime(332): Caused by: java.lang.IllegalArgumentException: width and height must be > 0

Any help would be appreciated.

Thanks.

Steve0212
  • 682
  • 2
  • 6
  • 23

1 Answers1

0

Use the content resolver to decode the bitmap instead. Refer to the answer at Android camera intent

Community
  • 1
  • 1
codejammer
  • 1,636
  • 1
  • 14
  • 27