使用缓冲区中的drawImage更新画布不使用drawImage应用操作
我使用缓冲方法来更新画布,问题是当我在缓冲区画布中绘制图像并将其应用到真实画布时,真实画布上没有图像。但我可以将其他任何东西应用到真实的画布上。
这是我的代码:
var ctx = $('#canvas')[0].getContext("2d"),
width = $("#canvas").width(),
height = $("#canvas").height(),
buffer = $("<canvas>")[0].getContext("2d");
ctx.canvas.width = width;
ctx.canvas.height = height;
buffer.canvas.width = width;
buffer.canvas.height = height;
var image = new Image();
image.src = "img/logo.png";
$(image).load(function() {
buffer.drawImage(image, 0, 0);
});
ctx.drawImage(buffer.canvas, 0, 0);
I use the buffering method to update a canvas, the thing is when I draw an Image in my buffer canvas and apply it to the real canvas there is no image at the real canvas. But I can apply anything else to the real canvas.
This is my code:
var ctx = $('#canvas')[0].getContext("2d"),
width = $("#canvas").width(),
height = $("#canvas").height(),
buffer = $("<canvas>")[0].getContext("2d");
ctx.canvas.width = width;
ctx.canvas.height = height;
buffer.canvas.width = width;
buffer.canvas.height = height;
var image = new Image();
image.src = "img/logo.png";
$(image).load(function() {
buffer.drawImage(image, 0, 0);
});
ctx.drawImage(buffer.canvas, 0, 0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用,因为这些事件正在发生:
如果您将 ctx.drawImage 行放在 onload: 内部,
它将按照您想要的方式工作。
It's not working because these events are occuring:
If you put the
ctx.drawImage
line inside of the onload:it would work like you want.