当前位置: 首页 > news >正文

做行程的网站推荐网站互联网推广

做行程的网站推荐,网站互联网推广,虚拟机wordpress安装教程视频教程,如何自己建造网站1. 图片网址url转化为bitmap 1.1. 方法一 通过 HttpURLConnection 请求 要使用一个线程去访问,因为是网络请求,这是一个一步请求,不能直接返回获取,要不然永远为null,在这里得到BitMap之后记得使用Hanlder或者EventBu…

1. 图片网址url转化为bitmap

1.1. 方法一 通过 HttpURLConnection 请求

  要使用一个线程去访问,因为是网络请求,这是一个一步请求,不能直接返回获取,要不然永远为null,在这里得到BitMap之后记得使用Hanlder或者EventBus传回主线程,不过现在加载图片都是用框架了,很少有转化为Bitmap的需求

    /*** 通过 网络图片 url 获取图片 Bitmap* @param photoUrl 网络图片 url*/private void requestWebPhotoBitmap(String photoUrl) {new Thread(() -> {HttpURLConnection connection = null;try {URL bitmapUrl = new URL(photoUrl);connection = (HttpURLConnection) bitmapUrl.openConnection();connection.setRequestMethod("GET");connection.setConnectTimeout(5000);connection.setReadTimeout(5000);// 判断是否请求成功if (connection.getResponseCode() == 200) {Message hintMessage = new Message();hintMessage.what = HANDLER_START_DOWNLOAD;hintHandler.sendMessage(hintMessage);InputStream inputStream = connection.getInputStream();imgBitmap = BitmapFactory.decodeStream(inputStream);Message message = showHandler.obtainMessage();showHandler.sendMessage(message);} else {Message hintMessage = new Message();hintMessage.what = HANDLER_NET_ERROR;hintHandler.sendMessage(hintMessage);}} catch (IOException e) {e.printStackTrace();} finally {if (connection != null) connection.disconnect();}}).start();}/*** 设置提示*/private final Handler hintHandler = new Handler(Looper.getMainLooper()){@Overridepublic void handleMessage(Message msg) {if(msg.what == HANDLER_START_DOWNLOAD)Toast.makeText(MainActivity.this, "获取图片中,请稍等", Toast.LENGTH_SHORT).show();else if(msg.what == HANDLER_NET_ERROR)Toast.makeText(MainActivity.this, "网络错误,请重试", Toast.LENGTH_SHORT).show();}};/*** 展示图片*/@SuppressLint("HandlerLeak")private final Handler showHandler = new Handler(Looper.getMainLooper()) {@Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);ivPhoto.setImageBitmap(imgBitmap); //填充控件}};

1.2. 方法二 通过 Glide

1.2.1. java

    /*** 获取 网络图片 Bitmap* @param imgUrl 网络图片url*/private void requestWebPhotoBitmap(String imgUrl) {Toast.makeText(MainActivity.this, "获取图片中,请稍等", Toast.LENGTH_SHORT).show();Glide.with(MainActivity.this).asBitmap().load(imgUrl).into(new CustomTarget<Bitmap>() {@SuppressLint("ClickableViewAccessibility")@Overridepublic void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {imgBitmap = resource;ivPhoto.setImageBitmap(imgBitmap)}@Overridepublic void onLoadCleared(@Nullable Drawable placeholder) {}});}

1.2.2. kotlin

   Glide.with(this).asBitmap().load(paramBean.userImg).into(object : CustomTarget<Bitmap?>() {override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap?>?) {val bitmap = resource}override fun onLoadCleared(placeholder: Drawable?) {}})

1.3. 调用

    private Bitmap imgBitmap = null;private ImageView ivPhoto;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ivPhoto = (ImageView) findViewById(R.id.photo);String imgUrl = "https://w.wallhaven.cc/full/l3/wallhaven-l3xk6q.jpg";requestWebPhotoBitmap(imgUrl);}
http://www.ds6.com.cn/news/67654.html

相关文章:

  • 有专做代金券的网站吗佛山全市核酸检测
  • 统计局网站集约化建设方案长沙网站建设公司
  • 庆云网站建设ihuibest网站查询站长工具
  • ps网站导航怎么做找做网站的公司
  • 百色做网站常州seo外包公司
  • 网站制作需要注意什么深圳全网推广平台
  • 有没有做产品团购的网站一个新手怎么做推广
  • 一流的南昌网站建设怎么关闭seo综合查询
  • 电子商务网站建设作用如何优化网页加载速度
  • 办公室装修设计网站怎样在百度上发表文章
  • wordpress图片在哪个文件夹东莞seo网络推广专
  • php做视频网站有哪些软件广告联盟怎么做
  • 什么网站做的好看的鹤壁seo推广
  • wordpress搜索结果优先标签重庆关键词seo排名
  • 计算机网站开发方向链友之家
  • 宁波建设工程报名网站此网站不支持下载视频怎么办
  • 网站域名备案查询系统网站开发软件有哪些
  • 西宁市城市道路建设规划网站自助建站网
  • wap手机网站源码足球比赛直播2021欧冠决赛
  • 给个网址2021年能看的廊坊seo网络推广
  • 网站代做多长时间网站seo是什么意思
  • 中国招标机构哪个网站做的好seo网络营销课程
  • 做公司简介网站许昌seo公司
  • 网站建设需要服务器么seo基础入门免费教程
  • 电视剧下载网站免费糖醋蒜怎样做b站推出的短视频app哪个好
  • 360安全浏览器做网站测试减少缓存设置黄页大全
  • 建网站多少钱一个月站长平台工具
  • 能自己做网站接业务吗b站好看的纪录片免费
  • 如何直到网站是用什么模板做的黄冈网站推广软件费用是多少
  • 广告公司电话广东网站seo营销