HTML5:尝试将画布复制到另一个画布时出现未知错误

发布于 2024-12-26 04:03:30 字数 568 浏览 6 评论 0原文

我不知道如何使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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悸初 2025-01-02 04:03:30

你会讨厌这个:你写的是 0,2 而不是 0.2。这就是它不起作用的原因。

我知道在许多欧洲国家/地区使用逗号作为小数,但 0.2 是它的用途。

通过以下方式检查代码的工作示例:

http://jsfiddle.net/zC4Wh/

You're gonna hate this: You wrote 0,2 instead of 0.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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文