UI上面生成的背景图片的宽高是550*900
生成的宽高也没错 可是生成的图片明显跟UI上的比例不对 这是怎么回事?
<view hidden="{{hidden}}" class='preview_wrapper'>
<image class="canvas3" src='{{prurl}}'></image>
</view>
.preview_wrapper {
z-index: 999999999999;
position: fixed;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
background: rgba(0, 0, 0, 0.4);
}
.canvas3{
width: 550rpx;
height: 900rpx;
}
const canvasCtx = wx.createCanvasContext('shareCanvas');
let width = 550; //UI上的宽度
let height = 900; //UI上的高度
let bg = that.data.canvasbg; //背景图片
canvasCtx.drawImage(bg, 0, 0, width, height);
canvasCtx.draw();
setTimeout(function() {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 550,
height: 900,
destWidth: 550,
destHeight: 900,
canvasId: 'shareCanvas',
success:res=>{
that.setData({
prurl: res.tempFilePath,
hidden: false
});
wx.hideLoading();
},
fail: function(res) {
console.log(res);
wx.hideLoading();
}
});
}, 2000);
canvas生成的
UI
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…