从Android中的自定义应用程序图像路径读取图像

时间:2013-10-08 05:21:53

标签: android image storage external

如何将以下路径中的图像作为位图读取?谢谢。

String path = "file:///storage/emulated/0/Pictures/MY_FILES/1371983157229.jpg";
String path = "file:///storage/sdcard0/Android/data/com.dropbox.android/files/scratch/Camera%20Uploads/2045.12.png";

3 个答案:

答案 0 :(得分:1)

应该使用==> BitmapFactory.decodeFile(pathName)方法。如果外部stroge中的文件声明了清单

中的权限

答案 1 :(得分:1)

在BitmapFactory中使用此方法,它将返回一个位图对象..

BitmapFactory.decodeFile(path);

答案 2 :(得分:0)

其他答案是正确的,但您可能会获得OutOfMemoryError high resolution张相机照片图片的 public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){ try { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int REQUIRED_HIGHT=HIGHT; //Find the correct scale value. It should be the power of 2. int scale=1; while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT) scale*=2; //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize=scale; return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) {} return null; } 张照片。所以为了避免这种情况,你可以使用以下功能

{{1}}

请参阅此错误https://stackoverflow.com/a/13226946/942224