圆角头像的实现
来源:互联网 发布:广东11选5遗漏数据 编辑:程序博客网 时间:2024/06/10 09:14
图片处理类:
public class ImageHelper { /** * 转换图片成圆形 * @param bitmap 传入Bitmap对象 * @return */ public static Bitmap toRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left,top,right,bottom,dst_left,dst_top,dst_right,dst_bottom; if (width <= height) { roundPx = width / 2; top = 0; bottom = width; left = 0; right = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap. createBitmap(width, height, Config. ARGB_8888 ); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect src = new Rect(( int)left, ( int )top, ( int)right, (int )bottom); final Rect dst = new Rect(( int)dst_left, ( int )dst_top, (int )dst_right, ( int)dst_bottom); final RectF rectF = new RectF(dst); paint.setAntiAlias( true ); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode( new PorterDuffXfermode(Mode. SRC_IN)); canvas.drawBitmap(bitmap, src, dst, paint); return output; } }
/* 将头像转为圆形 */ Resources res = getResources(); Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.head); head.setImageBitmap(ImageHelper.toRoundBitmap(bmp));
- 圆角头像的实现
- 圆角头像的实现
- 圆角头像的实现
- 实现头像的上传
- 圆角头像的制作
- 圆角头像的处理
- 圆角头像实现工具类
- fresco实现圆角、圆形头像
- 自定义实现圆头像
- 【Android】更换头像的实现
- 换头像的功能实现
- 精简版BitmapShader实现圆形头像和圆角方形头像
- Android 圆角图形和圆角头像的完美实现
- 我的Android笔记--使用BitmapShader实现可调灰色圆形、圆角头像
- 前端黑魔法--纯css折角头像的实现
- iOS裁切图片(圆头像的实现)
- 完美实现类似QQ的自拍头像、上传头像功能!
- iOS:圆形头像和菱形头像的实现
- Web 软件测试 Checklist 应用系列,第 4 部分: 内容、图片和按钮
- JAVA_WEB Oracle 10g学习: PL/SQL与Oracle间交互
- C++中浅拷贝与深拷贝之间的区别
- 重要的ssh命令
- Android动画实现
- 圆角头像的实现
- CLR 基础备忘 (纯个人复习备忘)
- linux中jdk的卸载与安装
- 继承扩展jQuery Mobile的初始化事件
- JAVA_WEB Oracle 10g学习: 本地动态SQL
- 怎么跟妻子解释面向对象
- 最近用到的informix sql,关于时间函数
- 深入jQuery Mobile的事件
- 常用的 SQL语句 汇总