使用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: ...
随机推荐
- CSU 1510 Happy Robot
1510: Happy Robot Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 19 Solved: 7 Description Input The ...
- No enclosing instance of type E is accessible.
No enclosing instance of type E is accessible. 静态方法(main)中调用内部类,会出现这样的问题: 学习了:https://www.cnblogs.c ...
- 仿小米简约Calculator
上个星期的时候,我想教我朋友做一个简单的app.想来想去教什么比較好.当时看见小米的计算器认为比較美丽,就想这个简单.然后就開始动手做了.我以为能够一个小时能够搞定.没想到花了快一天的时间. 哎.突然 ...
- JNI 实战全面解析
项目决定移植一款C++开源项目到Android平台,开始对JNI深入研究. JNI是什么? JNI(JavaNative Interface)意为Java本地调用,它允许Java代码和其他语言写的代码 ...
- Redis之创建
redis配置文件信息 public sealed class RedisConfigInfo { /// <summary> /// 可写的Redis链接地址 /// format:ip ...
- 分享关于浏览器对象 history对象
window.history.forward() == window.history.go(-1) //返回下一页 window.history.back() == window.history.go ...
- 关于Echarts表格插件的使用
<template> <div :style="{height:height,width:width}"></div> </templat ...
- 紫书 例题 9-9 UVa 10003 (区间dp+递推顺序)
区间dp,可以以一个区间为状态,f[i][j]是第i个切点到第j个切点的木棍的最小费用 那么对于当前这一个区间,枚举切点k, 可以得出f[i][j] = min{dp(i, k) + dp(k, j) ...
- Swift学习笔记(1)--基本语法
1.分号; 1>Swift不要求每个语句后面跟一个分号作为语句结束的标识,如果加上也可以,看个人喜好 2>在一行中写了两句执行语句,需要用分号隔开,比如 let x = 0; printl ...
- cogs 49. 跳马问题
49. 跳马问题 ★ 输入文件:horse.in 输出文件:horse.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 有一只中国象棋中的 “ 马 ” ,在半张 ...