您的位置:首页 > 其它

将一个图片的url地址转换为一个bitmap图片

2013-05-09 10:29 351 查看

转载▼

URL url = new URL(path);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setConnectTimeout(5000);

int max = conn.getContentLength();

InputStream is = conn.getInputStream();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

byte[] buffer = new byte[1024];

int len;

while ((len = is.read(buffer)) != -1) {

baos.write(buffer, 0, len);

}

byte[] result = baos.toByteArray();

return BitmapFactory.decodeByteArray(result, 0, result.length);

} catch (Exception e) {

e.printStackTrace();

return null;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐