且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置图像uri导致无法解码流:java.io.FileNotFoundException:

更新时间:2022-11-16 17:34:29

setImageURI()用于Android特有的内容URI. 平台,而不是用于指定Internet资源的URI.

setImageURI() is for content URIs particular to the Android platform, not URIs specifying Internet resources.

尝试在新线程中从Internet获取位图,然后将其添加到ImageView.像这样:

Try getting your bitmap from internet in a new thread an then add it to your ImageView. Like this:

uploadedImage.setImageBitmap(getImageBitmap(mDownloadUrl));


private Bitmap getImageBitmap(String url) {
        Bitmap bm = null;
        try {
            URL aURL = new URL(url);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
       } catch (IOException e) {
           Log.e(TAG, "Error getting bitmap", e);
       }
       return bm;
    } 

您还可以使用一个有用的库来设置名为Picasso的图像(内部和外部图像) http://square .github.io/picasso/

You also can use a useful library to set image (Internal and external images) called Picasso http://square.github.io/picasso/