createSelectorQuery 在正式发布版中无法进入回调,体验版可以
createNewImg: function () {
let t = this;
const query = this.createSelectorQuery().in(this)
query.select('#mycanvas').fields({
node: true,
size: true
}).exec((res) => {
console.log(res)
const canvas = res[0].node
const ctx = canvas.getContext('2d')
// 绘制图片:图片居中显示在 canvas 中
let imgWidth = t.data.imgWidth;
let imgHeight = t.data.imgHeight;
canvas.width = t.data.screen_width * t.data.ratio
canvas.height = t.data.screen_height * t.data.ratio
ctx.scale(1, 1);
let imageRatio = imgWidth / imgHeight
if (imageRatio > 1.25)
imageRatio = 1.25
let x = 0.1 * t.data.screen_width * t.data.ratio;
let y = (0.1 * t.data.screen_width * imageRatio + 30)
let w = 0.8 * t.data.screen_width * t.data.ratio
let h = (w / imageRatio)
let textHeight = 100 * t.data.ratio;
t.setData({
x,
y,
w,
h,
textHeight,
canvas,
ctx,
})
t.drawBack(x, y, w, h, textHeight, canvas, ctx)
})
},