您的位置:首页 > 其它

通过图片url显示图片在imageview上

2018-03-13 16:03 555 查看
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;
}


//或者是通过glide框架
Glide.with(this).load(url).bitmapTransform(
new GlideRoundTransform(this, 2)).placeholder(R.drawable.img_default)
.error(R.drawable.img_default
).into(mIvView);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐