setImageURI / setimagebitmap从网上获取的图像和显示图像视图 [英] setImageURI / setimagebitmap to fetch image from net and display in image view

查看:199
本文介绍了setImageURI / setimagebitmap从网上获取的图像和显示图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从某些URL净取图像,并显示在我的ImageView。
以下是code,我使用: -

I want to fetch image from net from some URL and show it in my ImageView. following is the code i am using :-

Bitmap bm = null;
    try {
         URL aURL = new URL("stringURL"); 
         URLConnection conn = aURL.openConnection();
         conn.connect(); 
         InputStream is = conn.getInputStream();
         BufferedInputStream bis = new BufferedInputStream(is);
         bm = BitmapFactory.decodeStream(bis);
         bis.close();
         is.close(); 
    }catch (Exception e) {
        // TODO: handle exception
}
    iv.setImageBitmap(bm);

但我不能获得图像

but i can not get the image

推荐答案

我认为错误是在

URL aURL = new URL("stringURL");

应该是不带引号

URL aURL = new URL(stringURL);

如果stringURL是有效的URL它会工作......

if stringURL is valid url it will work...

希望它帮助../

这篇关于setImageURI / setimagebitmap从网上获取的图像和显示图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆