当前位置:网站首页>canvas画图时的bug记录
canvas画图时的bug记录
2022-08-04 09:33:00 【尼克_张】
1.重复使用图片的onload事件中处理某些事,出现图片闪烁
在调用画图片的构造函数时,我们可以先在constructor中缓存图片
constructor(){
this.img = new Image();
this.img.src = require("xx");
}
然后再在方法中画图片
this.ctx.drawImage(this.img,width,height)
2.当画布上出现重叠的图像
this.canvasDom = document.getElementById("canvas");
this.ctx = this.canvasDom.getContext("2d");
const {
width, height } = this.canvasDom;
this.width = width;
this.height = height;
先把原先的画布信息存下来
this.imageData = this.ctx.getImageData(
0,
0,
this.width,
this.height
);
清空画布,把存储的画布信息放上去,再加上自己新的内容
ctx.clearRect(0, 0, this.width, this.height);
this.imageData &&
ctx.putImageData(
this.imageData,
0,
0,
0,
0,
this.width,
this.height
);
边栏推荐
猜你喜欢
随机推荐
暴力破解-破解 Apache BASIC 认证
leetcode二叉树系列(二)
蘑菇书EasyRL学习笔记
Win11系统重装用什么好 一键重装Win11教程
数据万象内容审核 — 共建安全互联网,专项开展“清朗”直播整治行动
学习在微信小程序中判断url的文件后缀格式
学习在php中分析switch与ifelse的执行效率
2022年制冷与空调设备运行操作特种作业证考试题库及模拟考试
leetcode经典例题——56.合并区间
Oracle怎么获取当前库或者同一台服务器上某几个库的数据总行数?
Layer 3 Switch/Router OSPF Configuration Details [Huawei eNSP Experiment]
【COS 加码福利】COS 用户实践有奖征文,等你来投稿!
罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍
Win11如何隐藏输入法悬浮窗?
Detailed explanation of telnet remote login aaa mode [Huawei eNSP]
学习使用php把stdClass Object转array的方法整理
基于cRIO-904X搭建Simulink与Labview环境
ansible部署脚本--亲测可用无坑
Detailed explanation of NAT/NAPT address translation (internal and external network communication) technology [Huawei eNSP]
RL学习笔记(一)