使用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赋值看是否可以正常显示,若可以则路径正确

 
 
参考:Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': - CSDN博客
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.的更多相关文章

  1. 解决 canvas 将图片转为base64报错: Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasEleme...

    问题描述 当用户点击分享按钮时,生成一张海报,可以保存图片分享到朋友圈,用户的图片是存储在阿里云的OSS,当海报完成后,执行.canvas.toDataURL("image/png" ...

  2. 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 ...

  3. 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 ...

  4. Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node ……

    解决办法是加一个等待时间即可解决问题: setTimeout(function () { you code }, );

  5. 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 ...

  6. 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 ...

  7. 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. 出现这个问题是构造 ...

  8. 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 ...

  9. Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

    canvas绘制图片,由于浏览器的安全考虑,如果在使用canvas绘图的过程中,使用到了外域的图片资源,那么在toDataURL()时会抛出安全异常: Uncaught SecurityError: ...

随机推荐

  1. select &amp; epoll

    同步.异步.堵塞和非堵塞差别 同步:发出一个功能调用时.在没有得到结果之前,该调用就不返回 异步:当一个异步过程调用发出后.调用者不能立马得到结果.实际处理这个调用的部件在完毕后.通过状态.通知和回调 ...

  2. 在Windows上调整SGA大小遭遇ora-27100、ora-27102错误的处理方法

    今天早上去一公司合作伙伴那里,协助处理他们某客户的数据库性能问题,那个库是Oracle 10.2.0.1的,前台业务系统是政府某机构查询系统,碰到的问题是首页展示很慢,与之相关的SQL语句查询结果须要 ...

  3. Java 8 时间日期库的20个使用演示样例

    除了lambda表达式,stream以及几个小的改进之外,Java 8还引入了一套全新的时间日期API,在本篇教程中我们将通过几个简单的任务演示样例来学习怎样使用Java 8的这套API.Java对日 ...

  4. TortoiseSvn安装的时候,将svn的命令行工具单独隔离出来

    https://stackoverflow.com/questions/2967176/where-is-svn-exe-in-my-machine The subversion program co ...

  5. 分享关于浏览器对象 history对象

    window.history.forward() == window.history.go(-1) //返回下一页 window.history.back() == window.history.go ...

  6. boost.property_tree的高级用法(你们没见过的操作)

    版权声明:本文为博主原创文章,未经博主允许不得转载. 前一阵写项目,终于将这个boost下的xml读取类完成了,由于网上对property_trees的讲解很少,最多也就到get_child这个层面, ...

  7. hdu1856 More is better (并查集)

    More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) ...

  8. HDU 5375 Gray code (简单dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题面: Gray code Time Limit: 2000/1000 MS (Java/Oth ...

  9. final使用方法

     final的作用随着所修饰的类型而不同 1.final修饰类中的属性或者变量 不管属性是基本类型还是引用类型.final所起的作用都是变量里面存放的"值"不能变. 这个值,对 ...

  10. HDU 4173 Party Location(计算几何,枚举)

    HDU 4173 题意:已知n(n<=200)位參赛选手的住所坐标.现要邀请尽可能多的选手来參加一个party,而每一个选手对于离住所超过2.5Km的party一律不去,求最多能够有多少个选手去 ...