首页 > 移动平台 > 详细

Android 网络图片Url 转 Bitmap

时间:2017-04-28 00:49:41      阅读:286      评论:0      收藏:0      [点我收藏+]

注意:该方法必须要在子线程中调用,因为涉及网络请求

public Bitmap getBitmap(String url) {
        Bitmap bm = null;
        try {
            URL iconUrl = new URL(url);
            URLConnection conn = iconUrl.openConnection();
            HttpURLConnection http = (HttpURLConnection) conn;
            
            int length = http.getContentLength();
            
            conn.connect();
            // 获得图像的字符流
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is, length);
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();// 关闭流
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return bm;
    }

 

Android 网络图片Url 转 Bitmap

原文:http://www.cnblogs.com/zhujiabin/p/6778355.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!