所以我一直试图在onRendered函数上加载一些图像到流星项目,该函数还包含许多其他确实渲染过的东西。
Template.Canvas.onRendered(function() {
this.blues = new Image();
this.blues.src = "bluesh.png";
}
然后在一个自动运行功能中,还包括其他一些东西,那里有
this.ctx.drawImage(this.blues, this.dotsPaint[i].xCntr - this.radius, this.dotsPaint[i].yCntr - this.radius, this.radius * 2, this.radius * 2);
启动并触发绘画代码时,我收到此错误:
控制台错误:无法在canvasrenderingcontext2d上执行drawimage 提供的htmlimageelement处于破碎状态。
我阅读了一些在线和看到过使用图片上传功能的建议,所以我已经完成了
this.blues = new Image();
this.blues.src = "bluesh.png";
this.blues.onload = function () {
this.imageLoadCheck++;
console.log("test");
};
从未触发onload函数。 图像文件与使用它的文件放在同一文件夹中 项目/进口/游戏 我也尝试将图像放在main.js的相同文件夹中,该文件夹导入了画布代码,但也没有。还尝试放置在不同的文件夹并更改为/..images/bluesh.png,我尝试将图像代码放在template.Canvas.onCreated而不是onRendered,没有任何效果。 是否有不同的方式在流星上加载图像?我错过了什么吗?
谢谢!
编辑:这里是完整的控制台错误:
Exception from Tracker recompute function:
debug.js:41 Error: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state.
at Error (native)
at .<anonymous> (localhost:3000/app/app.js?hash=f237cc69921b50eb7ae7894d886737d7ca6557f8:272:18)
at localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1875:20
at Function.Template._withTemplateInstanceFunc (localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3687:12)
at localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1873:29
at Object.Blaze._withCurrentView (localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2214:12)
at viewAutorun (localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1872:18)
at Tracker.Computation._compute (localhost:3000/packages/tracker.js?hash=b605200c15f3a57abb701c7cbc58ca5b0f2802d7:351:36)
at Tracker.Computation._recompute (localhost:3000/packages/tracker.js?hash=b605200c15f3a57abb701c7cbc58ca5b0f2802d7:370:14)
at Object.Tracker._runFlush (localhost:3000/packages/tracker.js?hash=b605200c15f3a57abb701c7cbc58ca5b0f2802d7:535:14)