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

Android中使用Glide加载圆形图像或给图片设置指定圆角

一、Glide加载圆形头像

效果
在这里插入图片描述
R.mipmap.head_icon是默认圆形头像

ImageView mImage = findViewById(R.id.image);
RequestOptions options = new RequestOptions().placeholder(R.mipmap.head_icon).circleCropTransform();
Glide.with(this).load("图像Uri").apply(options).into(mImage);

二、Glide给图像设置圆角

例子:设置图片圆角为10dp
效果
在这里插入图片描述

RequestOptions options = new RequestOptions().placeholder(R.drawable.capture_default).bitmapTransform(new RoundedCorners(dip2px(mContext, 10)));
Glide.with(this).load("图像Uri").apply(options).into(mImage);

单位转换方法

public static int dip2px(Context context, float dpValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (dpValue * scale + 0.5f);}public static int px2dip(Context context, float pxValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (pxValue / scale + 0.5f);}

三、完成,Nice!

http://www.lryc.cn/news/198274.html

相关文章:

  • Nginx 代理
  • uniapp(uncloud) 使用生态开发接口详情4(wangeditor 富文本, 云对象, postman 网络请求)
  • Halcon 中查看算子和函数的执行时间
  • Python中的With ...as... 作用
  • 腾讯云国际站服务器如何打开音频设备?
  • k8s day05
  • 微信小程序里报名链接怎么做
  • Kotlin中的逻辑运算符
  • 启智平台新建一个调试任务后,如何配环境,并提交镜像
  • 模糊测试面面观 | 车联网场景模糊测试解决方案
  • 超声波清洗机有没有平价又好用的推荐、平价好用超声波清洗机总结
  • 工控机通过485modbus转profinet网关与温度智能表通讯配置案例
  • 【网络】计算机网络基础概念入门
  • Node.js的crypto模块 加密
  • react+hooks使用
  • wsl2安装fsl
  • mac电脑zsh: command not found: adb
  • GitHub下载太慢的解决方案
  • 英语生活常用词,柯桥成人零基础英语培训
  • 【前端学习】—使用多种方式实现数组去重(六)
  • JAVACPU占用过高、内存泄漏问题排查
  • 2023年【公路水运工程施工企业安全生产管理人员】新版试题及公路水运工程施工企业安全生产管理人员模拟试题
  • 屏幕截图软件Snagit 2023 mac中文特点介绍
  • deepin操作系统下载
  • 【docker】查看容器日志
  • Vue使用Echarts建立知识图谱
  • 力扣(LeetCode)1726. 同积元组(C++)
  • LAXCUS分布式操作系统是怎么实现的?
  • 香港服务器的速度为什么比较快
  • PhotoShop批量压缩图片