canvas生成的图片不能覆盖整个屏幕,这是怎么回事?
发布于 6 年前 作者 renyong 7347 次浏览 来自 问答

canvas生成的图片不能覆盖整个屏幕,这是怎么回事?

4 回复

<view  wx:if="{{show==true}}" >

<canvas style=“width:100%;height:{{windowHeight}}px;” canvas-id=“myCanvas”></canvas>

</view>

save: function () {

let that = this;

wx.showLoading({

title: ‘正在生成’,

mask: ‘true’

})

that.setData({

show: true

})

that.drawimage(that.data.windowWidth, that.data.windowHeight)

setTimeout(() => {

wx.canvasToTempFilePath({

x: 0,

y: 0,

width: that.data.windowWidth,

height: that.data.windowHeight,

canvasId: ‘myCanvas’,

success: function (res) {

wx.hideLoading()

console.log(res.tempFilePath)

that.setData({

show:false

})

wx.previewImage({

urls: [res.tempFilePath],

})

}

})

},3000)

},

drawimage: function (width,height){

const ctx = wx.createCanvasContext(‘myCanvas’)

ctx.drawImage(’…/…/static/images/2.jpg’, 0, 0, width, height)

ctx.draw()

}

有一段黑

windowHeight 是从哪里读取的呢?尝试使用 getUserInfo 中的 screenHeight

windowHeight 就是获取手机屏幕的高度,然后设置canvas的高度为屏幕的高度,然后导出图也是canvas的高度,导出的图片的长度高度都是canvas的宽高,但在预览的时候下面就如上图有一段黑

你好,请提供一下能复现问题的简单代码示例。

回到顶部