为啥使用canvas绘制完成后会出现黑色边框
代码:
<canvas type="2d" id="canvasChessBoard"></canvas>
const query = wx.createSelectorQuery()
query.select('#canvasChessBoard')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
// ctx.drawImage(dataTemp.strPathImgChessboard, 0, 0, dataTemp.nCanvChessBoardWidth, dataTemp.nCanvChessBoardHeight)
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 100, 100)
})
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
<canvas type="2d" id="canvasChessBoard"></canvas>
const query = wx.createSelectorQuery()
query.select('#canvasChessBoard')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
// ctx.drawImage(dataTemp.strPathImgChessboard, 0, 0, dataTemp.nCanvChessBoardWidth, dataTemp.nCanvChessBoardHeight)
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 100, 100)
})
解决了吗?是偶发还是100%复现?
@官方