Android如何从服务器获取图片
16lz
2022-01-23
public static Bitmap getBitmapFromServer(String imagePath) {HttpGet get = new HttpGet(imagePath);HttpClient client = new DefaultHttpClient();Bitmap pic = null;try {HttpResponse response = client.execute(get);HttpEntity entity = response.getEntity();InputStream is = entity.getContent();pic = BitmapFactory.decodeStream(is); // 关键是这句代码} catch (ClientProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return pic;}
其中imagePath是你的图片路径,比如:http://localhost:8080/app/images/abc.jpg
最后可以将图片显示在手机上:
imageView.setImageBitmap(bitmap);
更多相关文章
- android剪切圆角图片的方法
- Android判断文件类型(视频、音频、图片等)
- Android(安卓)文件的选择
- android 网络获取图片并存储
- 23_传智播客Android视频教程_网络通信之网络图片查看器
- 使Activity以对话框的形式弹出来
- android直接从图片中对二维码编码解码
- Android如何获取asset目录下所有文件的路径
- Pycharm安装PyQt5的详细教程