正如Android的指南文件所说,我写了一个相机活动。我保存了照片,然后我只想知道这张照片的宽度和高度。但我无法通过 BitmapFactory.decodeStream 获得它。这是我的代码,有人可以帮助我吗?
private PictureCallback mPictureCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
//save the photo
File pictureFile = new File("/sdcard/test/test.jpg");
if(!pictureFile.exists()) {
try {
pictureFile.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
//get the photo's width and height
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
InputStream is = null;
try {
is = new FileInputStream("/sdcard/test/test.jpg");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(is != null) {
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
int picWidth = bitmap.getWidth();
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
CameraActivity.this.setResult(RESULT_OK);
CameraActivity.this.finish();
}
};