代码片段: https://developers.weixin.qq.com/s/MrqfgAmj7mDa
渐变文字在模拟器和ios上显示正常,但在安卓上面却不显示
const app = getApp()
Page({
data: {},
onLoad: function () {
// 通过 SelectorQuery 获取 Canvas 节点
wx.createSelectorQuery()
.select('#canvas')
.fields({
node: true,
size: true,
})
.exec(this.init.bind(this))
},
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)
const gradient = ctx.createLinearGradient(width * 0.66, height * 0.55, width * 0.7, height * 0.55)
gradient.addColorStop('0', 'rgba(213,92,119,1)')
gradient.addColorStop('1', 'rgba(255,173,97,1)')
ctx.fillStyle = gradient
ctx.fillText('这是一行文字', width * 0.64, height * 0.55)
const img = canvas.createImage()
img.onload = () => {
this._img = img
}
img.src = './car.png'
}})
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
代码片段,https://developers.weixin.qq.com/s/MrqfgAmj7mDa
复现流程: 导入代码片段,然后使用安卓手机扫描预览,渐变文字不显示,但如果用ios扫描,可以正常显示