繁体   English   中英

如何在一个javaScript onClick事件中检索画布图像并在函数中使用该图像?

[英]How can I retrieve a canvas image and use that image in a function all within one javaScript onClick event?

这是我希望将画布图像检索到@ img.src中的功能。

            function draw() {   
            img = new Image();  
            img.src = [user defined canvas image].png    
            fr1 = makeFrame(ctx,makeVect(400,0),makeVect(400,makeVect(0, 400));
            img.onload = function(){ //<< This Im not sure of <<<
                ctx.save(); 
                newPainter = cornerSplit(imagePainter,5);
                newPainter(fr1);     
                ctx.restore();
                ctx.save();
                newPainter(flipHorizLeft(fr1));
                ctx.restore();
                ctx.save();
                newPainter(flipVertDown(fr1));  
                ctx.restore();
                ctx.save();
                newPainter(flipVertDown(flipHorizLeft(fr1)));   
            }  
        }

从中检索图像的画布是:“ canvas2”,其上下文是“ context2”,其HTML句柄是“ imageCreate”

由于您措辞的方式,很难弄清楚您想要的是什么。 假设我猜对了,您希望document.getElementById(“ canvas2”)。toDataURL(“ image / png”)捕获画布的图像数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM