Android(安卓)ImageView显示网络图片
16lz
2022-04-02
阅读更多
String url = "http://192.168.1.114:9000/data/attachments/342ac65c103853433bec12409113b07eca8088b4.jpg";imgIV = (ImageView) findViewById(R.id.home_news_img_iv);bitmap= Tools.getBitMap(url);imgIV.setImageBitmap(bitmap);
package com.newsapp.util;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import android.graphics.Bitmap;import android.graphics.BitmapFactory;public class Tools {public static Bitmap getBitMap(String url){ URL myFileUrl = null; Bitmap bitmap = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl .openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } }
更多相关文章
- Android(安卓)TextView显示html图片
- Speed Up and Back Up Your Rooted Android(安卓)Phone
- android 監聽系統屬性變化的方法
- andorid RecyclerView下拉刷新,上拉加载更多
- android 客户端 smtp 协议发送数据
- android 连接CMWAP
- Android再按一次退出程序实现方法
- android 客户端 smtp 协议发送数据
- Android(安卓)打开pdf文档,没有阅读器链接到Google Play Store等