2015-10-08 138 views
0

我正在与fabric.js和创建一个定制的产品,但我不能保存图像和div的和存在于画布上... 我的问题是如何保持图像存在在画布上作为图像。 ?如何保存画布图像

<!-- EDITOR  --> 
<!--manipular div tranasparente--> 
<div id="shirtDiv" class="page" style="width: 530px; height: 630px; position: relative; background-color: rgb(255, 255, 255);"> 
    <!----> 
    <img id="tshirtFacing" src="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>"></img> 
    <!--**********************************************************--> 
    <div id="drawingArea" style="position: absolute;top: 100px;left: 160px;z-index: 10;width: 200px;height: 400px;"> 
     <!--area de canvas--> 
     <canvas id="lienzo" width=200 height="400" class="hover" style="-webkit-user-select: none;"></canvas> 
    </div> 

</div> 

Image

回答

1

HTMLCanvasElement.toDataURL()该方法返回包含在由所述类型参数(默认为PNG)指定的格式的所述图像的表示的数据的URI。返回的图像分辨率为96 dpi。

var canvas = document.getElementById("lienzo"); 
var data = canvas.toDataURL("image/jpeg"); 

希望这会帮助你。