アプリに写真を撮らせ、その写真を返して使用しようとしています。ただし、エミュレータと Nexus One の両方で例外がスローされます。
これが私のコードです:
private File temporaryCameraFile = new File("/sdcard/tmp.bmp");
写真を撮るためにメニューから選択した場合:
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);
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));
}
デコードファイル()
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;
}
}
decodeFile() では、最初のデコードで境界が正しく返されます。ただし、2 回目に呼び出すと、エミュレーターと Nexus One の両方で次のエラーが発生します。inJustDecodeBounds メソッドを使用せずにメインのデコードのみを実行するように decodeFile を更新しようとしましたが、これも失敗しました。また、ファイルを手動でデバイスから取り出しましたが、有効なビットマップです。
09-20 15:30:58.711: ERROR/AndroidRuntime(332): Caused by: java.lang.IllegalArgumentException: width and height must be > 0
どんな助けでも大歓迎です。
ありがとう。