安卓机上base64图片无法在微信中长按保存?

使用canvas合成一张图片,然后利用canvas.toDataURL()转换成图片的格式为base64

ios测试环境下,用微信端访问该h5页面,渲染的转换图片可以长按保存。

但是在安卓机上长按可以调出微信的保存图片的事件按钮,点击后却没有反应,也没有保存图片

发现问题出在这段代码上,因为canvas在安卓机上显示模糊问题,我加了这段代码,加完后就出现了在安卓机上点击保存后保存图片失败的情况。加了这段代码图变清楚了...但是不能保存了。是怎么回事?

          var devicePixelRatio = window.devicePixelRatio || 1
          var backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
            ctx.mozBackingStorePixelRatio ||
            ctx.msBackingStorePixelRatio ||
            ctx.oBackingStorePixelRatio ||
            ctx.backingStorePixelRatio || 1
          var ratio = devicePixelRatio / backingStoreRatio
          var oldWidth = clientWidth
          var oldHeight = clientWidth

          canvas.width = oldWidth * ratio
          canvas.height = oldHeight * ratio

          canvas.style.width = oldWidth + 'px'
          canvas.style.height = oldHeight + 'px'
阅读 8.1k
2 个回答
          var ratio = 2
          var oldWidth = clientWidth
          var oldHeight = clientWidth

          canvas.width = oldWidth * ratio
          canvas.height = oldHeight * ratio

          canvas.style.width = oldWidth + 'px'
          canvas.style.height = oldHeight + 'px'

把像素比改成定成死值2....就可以保存了

直接创建个img标签的dom对象,然后把base64填充到src的方式比较保险……定位什么的用类来做然后给加上就好。或者也可以提前在页面写好img结构隐藏掉,用的时候再填充src最后显示就行了。