压缩并设置圆形头像
来源:互联网 发布:数据下载 编辑:程序博客网 时间:2024/06/11 19:29
效果图:
1.设置布局属性:
<ImageViewandroid:scaleType="fitXY"/>
2.得到指定圆形的Bitmap对象
public static Bitmap circleBitmap(Bitmap source) {int width = source.getWidth();Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);Paint paint = new Paint();paint.setAntiAlias(true);canvas.drawCircle(width / 2, width / 2, width / 2, paint);//设置图片相交情况下的处理方式//setXfermode:设置当绘制的图像出现相交情况时候的处理方式的,它包含的常用模式有://PorterDuff.Mode.SRC_IN 取两层图像交集部分,只显示上层图像//PorterDuff.Mode.DST_IN 取两层图像交集部分,只显示下层图像paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));canvas.drawBitmap(source, 0, 0, paint);return bitmap;}
3.处理后显示
Picasso.with(this.getActivity()).load(user.getImageurl()).transform(new Transformation() { @Override public Bitmap transform(Bitmap source) {//下载以后的内存中的bitmap对象 //压缩处理 Bitmap bitmap = BitmapUtils.zoom(source, UIUtils.dp2px(62), UIUtils.dp2px(62)); //图形处理 bitmap = BitmapUtils.circleBitmap(bitmap); //回收bitmap对象 source.recycle(); return bitmap; } @Override public String key() { return ""; } }).into(ivMeIcon);
4.压缩图片:
public static Bitmap zoom(Bitmap source,float w,float h){ Matrix matrix = new Matrix(); matrix.postScale(w / source.getWidth(),h / source.getHeight()); Bitmap bitmap = Bitmap.createBitmap(source,0,0,source.getWidth(),source.getHeight(),matrix,true); return bitmap;}
阅读全文
0 0
- 压缩并设置圆形头像
- WPF圆形头像设置
- 设置头像圆形
- 设置用户圆形头像
- 设置圆形头像
- Android从服务器获取图片并设置圆形头像
- Android实现本地上传图片并设置为圆形头像
- Android-切换头像(设置圆形头像)
- iOS 设置头像为圆形
- 圆形头像设置Android 原代码
- IOS圆形头像的设置
- 圆形头像设置—CustomShapeImageView
- 自定义圆形头像 和 图片压缩
- Android圆形头像设置(实现相机、相册选择并裁剪)兼容6.0/7.0
- html5设置头像为圆形的
- iOS 圆角 圆形头像 设置方法
- IOS开发-设置头像(圆形)
- 调用系统相册,相机设置圆形头像
- Makefile实例
- Spring中注解@Bean、@Resource、@Component、@SpringStudy
- golang遍历结构体(struct)字段对应的值,切片(slice),字典(map)
- what fuck
- 相关学习网站
- 压缩并设置圆形头像
- Gzip压缩的HttpResponse解析
- LeetCode.341 Flatten Nested List Iterator
- C++学习笔记---引用
- Java读取.ini文件(二)
- 5G系统RAN架构解析之CU和DU的应用和功能切分方式
- 【Scikit-Learn 中文文档】广义线性模型
- protobuf 前端怎么使用
- jsp基本内容2