当前位置:网站首页>SurfaceView高性能绘制(四)代码实践篇-绘制多张图片
SurfaceView高性能绘制(四)代码实践篇-绘制多张图片
2022-04-21 08:54:00 【鲁迷那】
一、前言
上篇文章写了关于根据触屏绘制图片的文章SurfaceView高性能绘制(三)代码实践篇-根据触屏绘制图片,那么如果我们要把每次绘制的图片都保持住在界面上呢,该怎么实现?为了方便说明自己查阅单独写成一篇博文
二、代码实现
思路:把绘制信息弄成一个对象,然后把这个对象放在集合里面,然后进行轮询绘制
1、首先定义一个图像对象
//图像对象
public class DrawingItem{
int x, y;
boolean isVertical, isHorizontal;//运动方向(垂直方向、水平方向)
public DrawingItem(int x, int y, boolean isVertical, boolean isHorizontal) {
this.x = x;
this.y = y;
this.isVertical = isVertical;
this.isHorizontal = isHorizontal;
}
}
2、然后定义一个图像对象数组,把每次得到的图像对象添加进来
private List<DrawingItem> locations;//图像对象数组
Random random = new Random();
//方向随机生成。在触摸的位置创建一个新的条目,该条目的开始方向是随机的
DrawingItem drawingItem =
new DrawingItem(msg.arg1,msg.arg2,random.nextBoolean(),random.nextBoolean());
locations.add(drawingItem);
贴的是主要代码,locations对象自己在适当的位置实例化
3、最后根据图像对象数组进行迭代,循环绘图
//绘图
if(!isRunning){
return true;//线程没有运行,直接返回
}
//获取画布
Canvas lockCanvas = this.drawingHolder.lockCanvas();//获取加锁的画布(避免线程问题)
if(lockCanvas == null){
break;//如果画布为空,中断
}
lockCanvas.drawColor(Color.BLACK);//清空画布。这里设置画布为黑色
for(DrawingItem item : locations){//循环绘图
//lockCanvas.drawBitmap(iconBitmap, 0, 0, paint);
lockCanvas.drawBitmap(iconBitmap, item.x, item.y, paint);
}
this.drawingHolder.unlockCanvasAndPost(lockCanvas);//解锁画布
三、效果图、源码
(1)效果图

(2)源码
https://download.csdn.net/download/yudbl/10969302
版权声明
本文为[鲁迷那]所创,转载请带上原文链接,感谢
https://blog.csdn.net/yudbl/article/details/87865598
边栏推荐
- 51 单片机学习_2.1 独立按键控制LED亮灭
- L2-026 small generation (25 points)
- Buuctf [actf2020 freshman competition] include
- C language counting and sorting
- Penetration practice - dig a school site vulnerability (APP vulnerability)
- Convolution operation and cross correlation operation
- Notice on printing and distributing the administrative measures for the first edition of software product certification in Hunan Province
- 51 single chip microcomputer learning_ 1.1 turn on an LED
- uniapp 热更新和整包更新
- Characteristics of interactive multimedia applications
猜你喜欢

Simulated 100 questions and simulated examination of Shanghai safety officer C certificate examination in 2022
![[paper reading] [iccv 2021] rpnet: learning inner group relations on point clouds](/img/37/0a1eb88aa20a6a3c4586137066e28a.png)
[paper reading] [iccv 2021] rpnet: learning inner group relations on point clouds

中国移动的用户ARPU重新进入上升通道,员工薪酬也稳步上涨

Maya basic tutorial and basic operation explanation

渗透实战-无回显Rce-thinkphp5-Getshell

7.4 并行卷积神经网络 GoogleNet

【(强推)李宏毅2021/2022春机器学习课程】Unsupervised Learning - Linear Methods
What is the product power of the new modern paristi, a joint venture 7-seat SUV with large displacement?
![[MySQL] Based on linux-centos7 9 detailed installation tutorial](/img/25/7947dc6d8b5fa99124b69a90a70a27.png)
[MySQL] Based on linux-centos7 9 detailed installation tutorial

实战渗透-fofa-dirBrute-代码审计-构造poc-ueditor-解密-过waf-Godzilla
随机推荐
ZABBIX 5.4 server installation
Power grid enterprise standard B interface access record (I): Registration
BUUCTF[极客大挑战 2019]Havefun
Integrating sdl2 with ffmpeg to realize texture rendering of random blocks
7.3 卷积神经网络 NIN
51 single chip microcomputer learning_ 2.1 independent key control LED on and off
内网渗透-代理穿透-提权-注入-msf-中间件-域渗透-日志清除-学习资源
[(strongly pushed) Li Hongyi 2021 / 2022 spring machine learning course] unsupervised learning - linear methods
7.3 convolutional neural network Nin
加入log4j日志功能
[GYCTF2020]Blacklist
多线程小抄集(新编二)
Leetcode0824. 山羊拉丁文(simple,字符串处理)
Ue5 little knowledge point animation blueprint interface cannot copy new in editor
Enter four integers in descending order
PageRank-案例-机场
Latest system vulnerability -- omero Web cross site scripting vulnerability
Analyse de l'API d'interface de numéro personnel du robot Wechat PC
BUUCTF[HCTF 2018]WarmUp
Worker man passes parameters to the method in timer