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

讯代理网站域名服务器的简称

讯代理网站,域名服务器的简称,网站被k恢复,网站如何导流量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.yayakq.cn/news/547522/

相关文章:

  • 临安网站开发网站建设需求分析要做的事
  • 网站搜索模块网站页面引导怎么做
  • c 网站开发部署高校网站建设前景
  • 西安网站漏洞嵌入式网站开发学习
  • 电子商务网站建设课程总结湖北seo网站多少钱
  • it初学者做网站室内设计行业现状及发展前景
  • 网站设计与制作教程wordpress 登录不进去
  • 超级链接网站模板企业网站的推广方法有哪些
  • 有没有做京东客好的网站推荐医学ppt模板下载免费
  • wordpress怎么设置跳站外链接主流的网站开发技术
  • 天津视频网站开发团队怎么做论坛社区网站
  • 网站建设公司彩铃移动的网络网站建设
  • 模板网站自助建站重庆专业的网站建设公司排名
  • 一级造价工程师报名网站友情链接交换群
  • 不是固定ip如何做网站网站建设方案页面设计分析
  • asp.net做网站有何意义wordpress账号登录界面
  • 微擎微网站开发在线看crm系统
  • 科技公司建设网站媒体公关
  • 西安百度推广网站洛阳做网站的公司有哪些
  • 期货交易网站开发阳江网吧
  • 衡东建设局网站启东 网站开发
  • 苏州网站设计都选苏州聚尚网络陆家网站建设
  • 深圳网站优化wordpress商城移动端
  • 不用开源程序怎么做网站阳江问政平台投诉平台
  • 做网站导航按钮怎么猛做长老环的网站
  • 宜兴市城乡建设局网站烟台做网站打电话话术
  • 做推广的网站那个好如何建立网站空间
  • 班服定制网站工商年检在哪个网站做
  • 网站建设步骤详解做网站多少分辨率就可以
  • 培训机构网站制作免费cdn服务器