public static Bitmap getNetBitmap(String urlString) {
try {
//用URL封装链接地址;
URL url = new URL(urlString);
//用url打开链接
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//联网的状态码
int responseCode = urlConnection.getResponseCode();
if(responseCode ==200){
//链接上获取输入流
InputStream inputStream = urlConnection.getInputStream();
//把流直接转换成bitmap(系统提供的BitmapFactory)
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);//BitmapFactory是个工具类,系统提供的
return bitmap;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
解析图片
最新推荐文章于 2022-12-01 16:20:47 发布