从图库中取出图像并将其设置为图像视图

时间:2016-05-22 08:28:24

标签: java android android-bitmap

如何从图库中获取图像,选择图像后,将其设置为图像视图

Uri uri = data.getData()

InputStream is = null

try
  is = getContentResolver.openInputStream(uri)

catch (FileNotFoundException e)  
    e.printStackTrace();


Bitmap b = BitmapFactory.decodeStream(is);
imageView.setImageURI(uri);

在选择图片时,应用程序崩溃并发出错误 -

unable to decode stream : java.io.fileNotFoundException : 
open failed : ENONENT (No such file or directory)
resolveUri failed on bad bitmap uri

0 个答案:

没有答案