代码片段:https://https://developers.weixin.qq.com/s/itksKBmF7lfd
使用drawImage绘制图片,图片仅显示一小部分,原始图片:
显示状态:
实在找不到原因了,非常简单的代码:
JS:
const app = getApp()
Page({
data: {
isShowImage: true,
clientwidth: 360,
clientheight: 640,
pixelratio: 3,
ratio: 0,
src: ‘/index/1.jpg’
},
onLoad: function () {
var that = this;
that.canvas = wx.createCanvasContext(“image-canvas”, that)
that.canvas.drawImage(that.data.src, 0, 0, that.data.clientwidth, that.data.clientheight)
that.canvas.draw()
}
})
wxml:
<canvas canvas-id=“image-canvas” style=‘width:{{clientidth}}px; height:{{clientHeight}}px;’></canvas>