其他分享
首页 > 其他分享> > cesium 下导出canvas内的内容为图片并自动下载

cesium 下导出canvas内的内容为图片并自动下载

作者:互联网

该方法直接使用就可以,

// canvas导出画布内的内容
function saveToFile(scene) {
    let canvas = scene.canvas;
    let image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
    let link = document.createElement("a");
    let blob = dataURLtoBlob(image);
    let objurl = URL.createObjectURL(blob);
    link.download = "scene.png";
    link.href = objurl;
    link.click();
}

function dataURLtoBlob(dataurl) {
    let arr = dataurl.split(','),
        mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]),
        n = bstr.length,
        u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
}

标签:canvas,image,导出,arr,scene,let,cesium,link
来源: https://www.cnblogs.com/lambertlt/p/16373968.html