Android BitmapFactory.decodeFile()在尝试获取图像时返回null
更新:used Environment.getExternalStorageDirectory()感谢您提供的信息不要直接访问SD卡,请尝试通过Android BitmapFactory.decodeFile()在尝试获取图像时返回null,android,bitmapfactory,Android,Bitmapfactory,更新:used Environment.getExternalStorageDirectory()感谢您提供的信息不要直接访问SD卡,请尝试通过环境访问SD卡 像这样: String imageInSD = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg"; Bitmap bitmap = BitmapFactory.decodeFile(imageInSD); if(bitmap == n
环境
访问SD卡
像这样:
String imageInSD = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
if(bitmap == null){
Log.v("combine image", "null");
}else{
Log.v("combine image", "not null");
}
试试这个:
String imageDir = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(imageDir);
if(bitmap == null){
Log.v("combine image", "null");
}else{
Log.v("combine image", "not null");
}
但是,不应硬编码路径。使用
String imageInSD = "file:///mnt/sdcard/DCIM/Soovy/2089.jpg";
获取SD卡的根
Environment.getExternalStorageState()
你成功了吗?试试:
String imageInSD=Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+“DCIM/Soovy/2089.jpg”代码>yes Get正在工作,正如akashasia提到的,应该使用Environment.getExternalStorageDirectory()
String imageInSD = Environment.getExternalStorageState() + "/DCIM/Soovy/2089.jpg";