java 安卓_从SD卡获取图片
拍照SD卡的路径。 我的照片名是01。jpg
确保图片在SD卡中
public boolean fileIsExists(){
try{
File f1 = new File("/sdcard/01.jpg");
f1 = new File("01.jpg");
if(!f1.exists()){
return true;
}
}catch (Exception e) {
// TODO: handle exception
return false;
}
return true;
}
boolean file1 = fileIsExists();
如果图片在SD卡内,则将图片放入imageview
错误在下面的代码中
if (file1==true){
imageView = (ImageView)findViewById(R.id.image_view);
String myJpgPath = "/sdcard/01.jpg";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 0;
Bitmap bitmap = BitmapFactory.decodeFile(myJpgPath, options);//error here Cellphone can't run
imageView.setImageBitmap(bitmap);
}
# 1 楼答案
试试下面的代码
# 2 楼答案
更改+“sdcard/01.jpg”;至+“/01.jpg”
(并确保位图不重复局部变量。)
# 3 楼答案
按如下方式设置路径: