我一直在尝试不同的事情,我可以将照片保存在使用相机拍摄的SD卡中(而不是意图),但无法从SD卡中拾取同一张照片并将其放置在ImageView的。我总是得到一个空指针异常。显示从SD卡到ImageView的照片
不知道缺少了什么,希望有人能帮助我:
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
// Save the image JPEG data to the SD card
FileOutputStream fos = null;
String fileName = "";
try {
fileName = "/mnt/sdcard/DCIM/MyPicture.jpg";
fos = new FileOutputStream(fileName);
fos.write(data);
fos.close();
Toast.makeText(getBaseContext(), "Image saved:" ,
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
Log.e(TAG, "File Note Found", e);
Toast.makeText(getBaseContext(), "Image couldn't be saved.",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
Log.e(TAG, "IO Exception", e);
Toast.makeText(getBaseContext(), "Image couldn't be saved.",
Toast.LENGTH_LONG).show();
}
Bitmap bitmap = BitmapFactory.decodeFile(fileName);
Log.d(TAG, fileName);
mImageView.setImageBitmap(bitmap);
}
};
我已尝试过:
try {
Bitmap picture = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()
+ "/DCIM/MyPhoto.jpg");
mImageView.setImageBitmap(picture);
} catch (Exception e) {
Log.e("Error reading file", e.toString());
}
}
它保存图片,但试图把在去捕捉ImageView中的图像表示“Error reading file”
logcat:
个DDMS:
对不起大家了......头痛我忘了把mImageView =(ImageView的)findViewById(R.id.imageView1);
我是一个灾难:-)
使用文件名如String path = Environment.getExternalStorageDirectory()。toString()+“/ DCIM/MyPicture.jpg”; –
仍然无效 – Chris
将您的logcat粘贴到此处。 –