HTML5:尝试将画布复制到另一个画布时出现未知错误
我不知道如何使drawImage工作...它什么也没做(除了它抛出一个带有未定义描述的异常):
layerCtx.globalAlpha = 0,2; // same thing with this line commented
layerCtx.drawImage(cvs, 0 , 0);
我有2个画布,一个是图层,另一个用于使用鼠标绘制。我想将用户在第一个画布上绘制的内容保存到图层并应用不透明度... 我不会向您提供所有代码,但您必须知道以下代码可以工作:
layerCtx.putImageData(ctx.getImageData(0, 0, 800, 500), 0, 0);
但我不能将不透明度与前一个一起使用,因此正如其他 stackoverflow.com 相关问题中所建议的那样,我想使用使用画布元素绘制图像。
ctx 是我的画布 cvs 的上下文,
layerCtx 是我的画布 layer 的上下文
I can't figure how to make drawImage work... It just does nothing (except that it throws an exception with an undefined description) :
layerCtx.globalAlpha = 0,2; // same thing with this line commented
layerCtx.drawImage(cvs, 0 , 0);
I have 2 canvas, one is a layer and the other is for drawing using the mouse. I want to save what the user has drawn on the first canvas to the layer and apply opacity...
I won't give you all the code but you have to know that the following code works :
layerCtx.putImageData(ctx.getImageData(0, 0, 800, 500), 0, 0);
but I can't use opacity with the previous, so as it is advised in other stackoverflow.com related questions, I'd like to use drawImage with a canvas element.
ctx is the context for my canvas cvs,
layerCtx is the context fort my canvas layer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你会讨厌这个:你写的是
0,2
而不是0.2
。这就是它不起作用的原因。我知道在许多欧洲国家/地区使用逗号作为小数,但
0.2
是它的用途。通过以下方式检查代码的工作示例:
http://jsfiddle.net/zC4Wh/
You're gonna hate this: You wrote
0,2
instead of0.2
. That's why it isn't working.I know a comma is used as a decimal in a lot of European countries, but
0.2
is what its gotta be for this.Working example to check your code by:
http://jsfiddle.net/zC4Wh/