我在将图库中的图像带到我的应用程序时遇到了麻烦。
困难的部分是,在一些文章中,他们使用uri而不是路径,但在其他文章中反之亦然。
另外,我也不确定......当我从意图回归中得到Uri时,我应该使用光标来获取图像数据吗? (How to get Images from Cursor in android?)在其他一些参考文献中,他们只需使用'getPath()'方法就可以轻松完成。
我需要路径还是uri?或者只有其中一个?
我现在很困惑..
始终使用Uri:
File file = new File(uri.getPath());
然后
Bitmap bitmap= BitmapFactory.decodeFile(file.getAbsolutePath());
当你有位图时只需将其加载到ImageView
imageView.setImageBitmap(bitmap);