I wrote a camera activity as Android's guide documents says. I saved the photo, then I just want to know the width and height of this photo. But I can't get it with BitmapFactory.decodeStream. Here's my code, anybody can help me?
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();
}
};
Is this solution working for you ?
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
//Returns null, sizes are in the options variable
BitmapFactory.decodeFile("/sdcard/image.png", options);
int width = options.outWidth;
int height = options.outHeight;
//If you want, the MIME type will also be decoded (if possible)
String type = options.outMimeType;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments