我将相机图像保存在前缀路径上,例如:
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 文件,则会出现同样的错误