保存画布从视频图像生成的图像不保存

时间:2016-01-27 17:09:20

标签: javascript html5 video canvas

我使用以下代码通过canvas方法生成图像格式视频,并且工作正常并显示图像格式视频

如何在服务器中保存该图像,

    <video>
        <source src="1.mp4" type="video/mp4">
    </video>
    <canvas>
    </canvas>
    <img id="screenshot" />
    <script>
    var context = canvas.getContext('2d');
    context.fillRect(0, 0, w, h);
    context.drawImage(video, 0, 0, w, h);
    var dataURL = canvas.toDataURL();
    document.getElementById('screenshot').src = dataURL;

保存图片的脚本

function saveCanvas('canvas','pat/' , '.jpg', options) {
                    return Task.spawn(function * () {
                    var reader = new FileReader;
                            var blob = yield new Promise(accept = > canvas.toBlob(accept, type, options));
                            reader.readAsArrayBuffer(blob);
                            yield new Promise(accept = > { reader.onloadend = accept });
                            return yield OS.File.writeAtomic('pat/', new Uint8Array(reader.result),
                            { tmpPath: 'pat/' + '.tmp' });
                    });
                            }

    </script>

有没有办法用随机名称保存图像文件

0 个答案:

没有答案