我有一个代码,它结合了多个画布并将它们保存到一个图像文件中。虽然这适用于非移动设备,但我在移动设备上对其进行了测试,虽然生成了图像,但打开文件会给您一条消息,提示“图像_无法显示,因为它包含错误。”
这是转换为图像的代码:
<script type='text/javascript'>
window.addEventListener('load', function() {
'use strict';
var src = document.getElementById('src');
var dst = document.getElementById('dst');
var dst1 = document.getElementById('dst1');
var input = src.getContext('2d');
var output = dst.getContext('2d');
var output1 = dst1.getContext('2d');
dst.width = dst_w;
dst.height = dst_h;
dst1.width = dst1_w;
dst1.height = dst1_h;
var img=document.getElementById("scream");
input.drawImage(img,0,0);
var sprkl = document.getElementById('sprkl');
var output_s = sprkl.getContext('2d');
input.drawImage(document.getElementById('sparkle'),0,0,150,150);
input.drawImage(document.getElementById('circle'),0,0,<?php echo $lenssize.",".$lenssize.",".$left.",".$top.",".$dia.",".$dia; ?>);
input.drawImage(document.getElementById('circle1'),0,0,<?php echo $lenssize.",".$lenssize.",".$left1.",".$top1.",".$dia1.",".$dia1; ?>);
function gonext() {
var a = document.getElementById('src');
var dataURL = a.toDataURL();
$.post("save.php?filen=<?php echo $filen; ?>", {data: a.toDataURL("image/png")})
window.setTimeout(function() {
document.frmnext.submit();
}, 10000);
}
<div style="position: relative; z-index: 2">
<canvas id="src" width="<?php echo $width; ?>" height="<?php echo $height; ?>"></canvas>
<canvas id="sprkl" style="position: absolute; z-index: 3;"></canvas>
<canvas id="dst" style='position: absolute; z-index: 3'></canvas>
<canvas id="dst1" style='position: absolute; z-index: 3'></canvas>
</div>