我将相机图像保存在前缀路径上,如:
String path = Environment.getExternalStorageDirectory().getPath()+/*myFolder&myFileName*/;
哪个正确保存在
中/storage/emulated/0/myapp/target060613_112341.jpg
然后我想使用以下代码将此图像放入ImageView中:
public void addImageToGallery(String path) {
ImageView imv = new ImageView(mGUIView.getContext());
Bitmap bitmap = BitmapFactory.decodeFile(path);
imv.setImageBitmap(bitmap);
imv.setAdjustViewBounds(true);
imv.setMaxHeight(100);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.RelativeImageGallery);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lp.addRule(RelativeLayout.ALIGN_LEFT);
rl.addView(imv, lp);
}
但是当调用BitmapFactory.decodeFile(path)时出现问题...函数返回错误,说明没有这样的文件或目录(ENOENT)
我的清单中还有w / r权限:
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
如果我尝试在内部路径(getFilesDir().getAbsolutePath()
)上存储和检索jpg文件,则会出现同样的错误
答案 0 :(得分:1)
问题解决了在清单文件中添加:
uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"
uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"