首页 > 其他 > 详细

Cesium截图功能

时间:2020-04-21 16:14:47      阅读:304      评论:0      收藏:0      [点我收藏+]

首先安装  canvas2image 

npm install canvas2image --save

因为项目基于vue,所以需要在canvas2image的最后面 加上

export default Canvas2Image

然后在页面中引入canvas2image.js

重点: 还需要在cesium初始化中添加如下代码(若是不添加,截图出来的图片是全黑的)

       contextOptions: {
          webgl:{
            alpha: true,
            depth:true,
            stencil:true,
            antialias:true,
            premultipliedAlpha:true,
            //通过canvas.toDataURL()实现截图需要将该项设置为true
            preserveDrawingBuffer:true,
            failIfMajorPerformanceCaveat:true
          }
        }

技术分享图片

 

最后

        var canvas = this.viewer.scene.canvas;
        var imageWidth = 800;
        var img = canvas2image.convertToImage(canvas, imageWidth, imageWidth * canvas.height / canvas.width,‘png‘);
        var loadImg = document.createElement(‘a‘)
        loadImg.href = img.src
        loadImg.download = ‘earth‘
        loadImg.click()

这样就可以实现cesium的截图功能了

Cesium截图功能

原文:https://www.cnblogs.com/reround/p/12745079.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!