0

我有一个代码,它结合了多个画布并将它们保存到一个图像文件中。虽然这适用于非移动设备,但我在移动设备上对其进行了测试,虽然生成了图像,但打开文件会给您一条消息,提示“图像_无法显示,因为它包含错误。”

这是转换为图像的代码:

<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>
4

2 回答 2

0

为了支持toDataURL尝试这个,因为我认为,导出图像与base64这样的数据字符串存在问题......

我的项目有同样的问题,我找到了这个解决方案

$('.jSignature').attr('id','image_b_id');
var canvas_1 = document.getElementById('image_b_id');
var image_b_base64 = canvas_1.toDataURL();

当我创建时jSignature Canvas,我可以在许多移动设备上运行。但是其他一些设备(例如 Galaxy mini)出现错误...

于 2013-10-02T21:10:18.313 回答
0

非常感谢您抽出宝贵时间回复我的问题,但是我找到的解决方案在这里

我只是添加了 js 文件,仅此而已。

再次感谢 :)

于 2013-10-03T06:24:05.403 回答