const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
screenWH: [],
isBottomShow:true
},
bindViewTap: function() {
},
getScreenWH: function (callback) {
try {
var res = wx.getSystemInfoSync();
var wh = this.data.screenWH;
wh.push(res.windowWidth);
wh.push(res.windowHeight);
if (callback){
callback();
}
} catch (e) {
}
},
onLoad: function () {
var that = this;
that.getScreenWH(function(){
that.draw();
});
},
draw:function(){
var that = this;
var context = wx.createCanvasContext("canvas");
context.setFontSize(30);
context.save();
context.setFillStyle('black');
context.fillText('Hello', 30, 30);
context.restore();
context.save();
context.setTextAlign('center');
context.setFillStyle('blue');
context.fillText('Hello2', 30, 100);
// context.setTextAlign('left');//恢复左对齐可以正常显示 context.restore();
context.save();
context.setFillStyle('red');
context.fillText('Hello3', 30, 60);
context.restore();
context.draw(false, function(){
wx.canvasToTempFilePath({
canvasId: 'canvas',
success: function (res) {
setTimeout(function () {
that.setData({
isBottomShow: false
});
var ctx = wx.createCanvasContext("canvas_above");
ctx.drawImage(res.tempFilePath, 0, 0, that.data.screenWH[0], that.data.screenWH[1]);
ctx.draw();
}, 5 * 1000);
}
});
});
}
})
|