使用wpaint绘图软件时:Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
使用wpaint绘图软件时:Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
一、总结
一句话总结:通过删除法和最简单模式找错,发现是style="display: none;"这个位置引发的错误
<div class="student_note_type_item" id="student_note_type_picture1" style="display: none;">
{include file="common/wpaint" /}
</div>
1、Uncaught DOMException表示什么?
Uncaught DOMException表明未获取dom元素
2、排查错误的方法?
删除法:删除法删除代码以方便找到冲突代码
(因为有些情况下是好的,多了代码就出错,哪肯定是多的代码的问题)
最简单模式:查看最简单模式下是不是好的,如果是,逐步增加代码查找冲突源
3、使用wpaint绘图软件时:Uncaught DOMException出错的教训是什么?
给外部插件加的样式也很有可能是外部插件出错的原因
就是外部插件出错,不仅可能是js错误,css错误也非常常见
二、Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D':
问题:
Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D':The HTMLImageElement provided is in the 'broken' state.
分析:
Uncaught DOMException表明未获取dom元素
The HTMLImageElement provided is in the 'broken' state.表明元素在获取过程中被中断了,也即元素可能没有正确获取
图片路径不正确导致图片未正确获取也将导致该错误
代码:
HTML文件
<!DOCTYPE>
<html>
<head>
<mata name="viewport" content="width=device-width,initial-scale=1">
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
</head>
<body>
<div>
<canvas id="start" width="800" height="600">
</canvas>
</div>
<img src="./img/girl.jpg" id="img" style="display:none"/> <!--正确路径-->
<script type="text/javascript" src="js/commonFunctions.js"></script>
<script type="text/javascript" src="js/star.js"></script>
</body>
</html>
start.js:
var can;
var ctx;
var width;
var height;
var imgGirl=new Image();
// $(document).ready(function(){
// init();
// })
document.body.onload=init;
function init(){
can=document.getElementById("start");
ctx=can.getContext("2d");
width=can.width;
height=can.height;
imgGirl.src="../img/girl.jpg"//注意文件路径 正确路径为:./img/girl.jpg
gameLoop();
}
function drawBg(){
ctx.fillStyle="#393550";
ctx.fillRect(0,0,width,height);
}
/** [gameLoop 刷新画布] */
function gameLoop(){
window.requestAnimFrame(gameLoop);
drawBg();
drawImg();
}
//根据设备性能进行调用
function drawImg(){
// star.js:39 Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D':
// The HTMLImageElement provided is in the 'broken' state.
// 分析:Uncaught DOMException表明未获取dom元素
// The HTMLImageElement provided is in the 'broken' state.表明元素在获取过程中被中断了,也即元素可能还在加载中
ctx.drawImage(imgGirl,100,100)
}
解决办法:
先判断图片路径在js中是否正确:
在html中添加img标签,通过js赋值看是否可以正常显示,若可以则路径正确
https://blog.csdn.net/tjj3027/article/details/78914071
三、使用wpaint绘图软件时:Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
通过删除法和最简单模式逐步缩小错误代码范围找错,发现是style="display: none;"这个位置引发的错误
1 <div class="student_note_type_item" id="student_note_type_picture1" style="display: none;">
2 {include file="common/wpaint" /}
3 </div>
{include file="common/wpaint" /}里面是wpaint
使用wpaint绘图软件时:Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.的更多相关文章
- 解决 canvas 将图片转为base64报错: Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasEleme...
问题描述 当用户点击分享按钮时,生成一张海报,可以保存图片分享到朋友圈,用户的图片是存储在阿里云的OSS,当海报完成后,执行.canvas.toDataURL("image/png" ...
- wordpress 点击文章图片 不能编辑(chrome下面) wordpress Uncaught DOMException: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 1.
说明:在chrome下面,编辑文章插入的图片,点击到图片上面,没有菜单显示. 报错: tinymce.min.js:10 Uncaught DOMException: Failed to execut ...
- Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported
Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may no ...
- Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node ……
解决办法是加一个等待时间即可解决问题: setTimeout(function () { you code }, );
- mui.min.js:7 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load
mui框架做的微信公众号网页,在上传数据的时候报了这个错,async: true,//将false改为true就可以了 https://blog.csdn.net/liuzp111/article/d ...
- vue 运行项目时,Uncaught (in promise) DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
npm run dev 运行项目后 验证码显示不出来 并报错 Uncaught (in promise) DOMException: Failed to execute 'open' on 'XML ...
- Uncaught DOMException: Failed to construct 'WebSocket': The URL 'xxx.xxx.com/' is invalid.
Uncaught DOMException: Failed to construct 'WebSocket': The URL 'xxx.xxx.com/' is invalid. 出现这个问题是构造 ...
- patchUpload.vue?5e29:406 Uncaught (in promise) DOMException: Failed to execute 'readAsArrayBuffer' on 'FileReader': The object is already busy reading Blobs.
patchUpload.vue?5e29:406 Uncaught (in promise) DOMException: Failed to execute 'readAsArrayBuffer' o ...
- Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
canvas绘制图片,由于浏览器的安全考虑,如果在使用canvas绘图的过程中,使用到了外域的图片资源,那么在toDataURL()时会抛出安全异常: Uncaught SecurityError: ...
随机推荐
- 题解 P3243 【[HNOI2015]菜肴制作】
这道题看起来就是个裸的拓扑排序,抄上模板就能AC. 上面这种想法一看就不现实,然鹅我第一次还真就这么写了,然后被随意hack. 我们需要注意一句话: 现在,酒店希望能求出一个最优的菜肴的制作顺序,使得 ...
- 洛谷—— P2419 [USACO08JAN]牛大赛Cow Contest
https://www.luogu.org/problem/show?pid=2419 题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, convenie ...
- Qt中事件分发源码剖析
Qt中事件分发源码剖析 Qt中事件传递顺序: 在一个应该程序中,会进入一个事件循环,接受系统产生的事件,而且进行分发,这些都是在exec中进行的. 以下举例说明: 1)首先看看以下一段演示样例代码: ...
- Nios II 系统时钟timestamp的应用
在用Nios II做外设时序驱动的时候,经常会用延时函数.有时会常使用某个FPGA芯片和时钟,比如笔者一直使用的芯片是cyclone系列 EP2C35F484C8N,PLL输入SOPC时钟是50M.因 ...
- powerpoint(ppt) 的制作
1. 幻灯片母版 所谓母版,是共享的部分,也即想在全部幻灯片重复出现的元素. 首先,幻灯片母版在菜单栏的[视图]选择[幻灯片母版]显示和查看. 通过幻灯片母版的编辑和设计,可进一步: 在幻灯片的相关位 ...
- 21.MFC进制转换工具
相关代码:链接:https://pan.baidu.com/s/1pKVVUZL 密码:e3vf #include <stdlib.h> #include <stdio.h> ...
- 学习推荐《精通Python网络爬虫:核心技术、框架与项目实战》中文PDF+源代码
随着大数据时代的到来,我们经常需要在海量数据的互联网环境中搜集一些特定的数据并对其进行分析,我们可以使用网络爬虫对这些特定的数据进行爬取,并对一些无关的数据进行过滤,将目标数据筛选出来.对特定的数据进 ...
- fgrep---指定的输入文件中的匹配模式的行
fgrep命令是用来搜索 file 参数指定的输入文件(缺省为标准输入)中的匹配模式的行.fgrep 命令特别搜索 Pattern 参数,它们是固定的字符串.如果在 File 参数中指定一个以上的文件 ...
- Objective-C method及相关方法分析
## Objective-C method及相关方法分析 转载请注名出处 [http://blog.csdn.net/uxyheaven](http://blog.csdn.net/uxyheaven ...
- 用ElasticSearch,LogStash,Kibana搭建实时日志收集系统
用ElasticSearch,LogStash,Kibana搭建实时日志收集系统 介绍 这套系统,logstash负责收集处理日志文件内容存储到elasticsearch搜索引擎数据库中.kibana ...