当前位置:网站首页>Set round avatar -- canvas and paint
Set round avatar -- canvas and paint
2022-07-18 08:48:00 【Android Xiaobai~】
java Code :
Set related variables :
private Bitmap bitmap;
private Paint mPaint;
private Path mPath; Because it needs to be used clip Series of functions , want Disable hardware acceleration , Otherwise, it will not produce any effect .
setLayerType(LAYER_TYPE_SOFTWARE,null);Can't be in onDraw Function , You need to initialize .
private void init() {
setLayerType(LAYER_TYPE_SOFTWARE,null);
bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.a);
mPaint = new Paint();
mPath = new Path();
int width = bitmap.getWidth();
int height = bitmap.getHeight();
mPath.addCircle(width/2,height/2,width/2,Path.Direction.CCW);
}rewrite onDraw() function :
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.clipPath(mPath);
canvas.drawBitmap(bitmap,0,0,mPaint);
canvas.restore();
}Last but not least xml Just import it into the layout file :
<com.example.vacationtest.CircleTest
android:layout_width="120dp"
android:layout_height="120dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />The operation effect is as follows :

original image ( You can search Baidu map by yourself )

边栏推荐
- HMS Core图形图像技术展现最新功能和应用场景,加速构建数智生活
- 单身杯,Web:web签到
- 【Luogu_P4556】 [Vani有约会]雨天的尾巴 /【模板】线段树合并
- Several common methods of database table query in SAP ABAP system
- Connecting with enterprise wechat, customer relationship management can also be very simple!
- Qt(十三)QChart绘制折线图
- 使电脑拥有公网IP方法
- Top ten cases of "enterprise digital transformation"!
- (2021牛客多校三)J-Counting Triangles(思维)
- 《MySQL高级篇》二、逻辑架构分析
猜你喜欢

MySQL about the installation process of zip installation package

OpenCV 教程 01:简介与安装,图片与视频的基本操作
![【Luogu_P4556】 [Vani有约会]雨天的尾巴 /【模板】线段树合并](/img/e3/c2b3d45c6a0d1f7ff0b8b7bccf2106.png)
【Luogu_P4556】 [Vani有约会]雨天的尾巴 /【模板】线段树合并

About March 2022, apt-c-41 disguised as winrar Exe attack terminal side emergency response troubleshooting point

(2021牛客多校五)B-Boxes(概率期望)

(2021牛客多校五)D-Double Strings(乘法原理+动态规划)

单身杯,Web:web签到

如何从HoloLens中拍摄出满意的照片/视频

【集训DAY1】Spy dispatch【最小生成树】

电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
随机推荐
Qt(五)元对象特性
【Luogu_P4556】 [Vani有约会]雨天的尾巴 /【模板】线段树合并
Logic of archives | holonomic distinction and examples
数据库:使用WHERE语句进行检索(头歌)
(2021牛客多校五)K-King of Range(单调队列/ST表)
PostgreSQL自带的单机并行查询的执行方法是什么?
当使用single-branch clone仓库后,如何添加跟踪的远程分支?
Develop command line tools
Qt(六)数值与字符串转换
Windows10 reset MySQL user password
事件4624是登录成功!?!真的如此吗?
ncnn 推理框架安装;onnx转ncnn
Use honeypots to counter the blue team
开发命令行工具
docker mysql容器如何开启慢查询日志
Swift value type and reference type
Common differences between MySQL and Oracle (2)
SQL多表查询
Application of spectral normalization in Gan with LSTM as discriminator (tensorflow2)
OpenCV 教程 01:简介与安装,图片与视频的基本操作