Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获得;“打印屏幕”;来自kineticJS部门_Javascript_Html_Kineticjs - Fatal编程技术网

Javascript 获得;“打印屏幕”;来自kineticJS部门

Javascript 获得;“打印屏幕”;来自kineticJS部门,javascript,html,kineticjs,Javascript,Html,Kineticjs,我使用kineticJS实现了一个图表工具,现在我想用从kineticJS阶段捕获的一些图像生成一个PDF 看起来是这样的: <div id="canvasDrawingArea" style="height: 650px; width: 1150px;"> <div class="kineticjs-content" role="presentation" style="position: relative; display: inline-block; width: 115

我使用kineticJS实现了一个图表工具,现在我想用从kineticJS阶段捕获的一些图像生成一个PDF

看起来是这样的:

<div id="canvasDrawingArea" style="height: 650px; width: 1150px;">
<div class="kineticjs-content" role="presentation" style="position: relative; display: inline-block; width: 1150px; height: 650px;">
<canvas width="1150" height="650" style="padding: 0px; margin: 0px; border: 0px; position: absolute; top: 0px; left: 0px; width: 1150px; height: 650px; background: transparent;"></canvas>
<canvas width="1150" height="650" style="padding: 0px; margin: 0px; border: 0px; position: absolute; top: 0px; left: 0px; width: 1150px; height: 650px; background: transparent;"></canvas>
</div>
</div>

我的kineticJS分区如下所示:

<div id="canvasDrawingArea" style="height: 650px; width: 1150px;">
<div class="kineticjs-content" role="presentation" style="position: relative; display: inline-block; width: 1150px; height: 650px;">
<canvas width="1150" height="650" style="padding: 0px; margin: 0px; border: 0px; position: absolute; top: 0px; left: 0px; width: 1150px; height: 650px; background: transparent;"></canvas>
<canvas width="1150" height="650" style="padding: 0px; margin: 0px; border: 0px; position: absolute; top: 0px; left: 0px; width: 1150px; height: 650px; background: transparent;"></canvas>
</div>
</div>

我想要实现的是一个像下面这样的图像,我在我的计算机上做了一个打印屏幕,但我不知道如何通过代码实现这一点:

我查过这个信息了

但在我的例子中,我有两个画布,因为我有两层

我该怎么做? 我真的需要这样做,这可能吗(我真的希望如此)


提前感谢各位。

您可以将舞台导出为图像:
var stageImage=myStage.toImage()

如果需要导出的层少于舞台上的所有层,则需要将所有所需层展平到单个画布中

  • 使用
    document.createElement
    创建内存画布,并将新画布元素的大小设置为与舞台相同

  • 所有KineticJS层实际上都是画布元素。在内存画布上绘制每个层。您可以使用
    var layer1Canvas=layer.getCanvas()
    获取对每个层画布的引用,然后使用
    context.drawImage(layer1Canvas,0,0)
    [与layer2相同]将该画布绘制到内存画布


此时,您的两个层已展平到一个画布上,可以使用MemoryCanvas.toDataURL

导出该画布,非常感谢!在你的指导和其他一些我在stackoverflow上检查过的东西的帮助下,我能够实现我想要的。