在自定义组件中,用canvas画了一个统计图,在模拟器上效果正常,一到真机上文字和线段效果就模糊起来了。
真机
模拟器
canvas长宽已经和style中长宽设置一直,应该不存在拉伸的情况,况且虚拟机上显示也正常。
获取canvas方式。
wx.createSelectorQuery().in(this)
.select('#scatterCanvas')
.fields({
node: true,
size: true,
})
.exec(function(res){
const canvas = res[0].node
...
}
canvas设置成两倍试试
init(res) {
const width = res[0].width
const height = res[0].height
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = width * dpr
canvas.height = height * dpr
ctx.scale(dpr, dpr)
}
可能是手机像素不高?