从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卡内,则将图片放入图片视图。
错误在以下代码中
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);
}
答案 0 :(得分:0)
试试以下代码。
File f = new File("/mnt/sdcard/01.jpg");
ImageView mImgView1 = (ImageView)findViewById(R.id.imageView);
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
mImgView1.setImageBitmap(bmp);
答案 1 :(得分:0)
设置你的路径:
String myJpgPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"folderName/01.jpg";
答案 2 :(得分:0)
更改+" sdcard / 01.jpg&#34 ;;到+" /01.jpg" ;;
(并确保位图位图不会重复局部变量。)
if (file1==true){
String myJpgPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/01.jpg";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 0;
Bitmap bitmap = BitmapFactory.decodeFile(myJpgPath, options);
imageView.setImageBitmap(bitmap);
}