canvas绘画
wxml canvas代码
。
<canvas class='canvas' style="width:{{code_w}}px;height:{{code_w}}px;" canvas-id='canvas' bindlongtap='save'></canvas>
<image class='canvas' src="{{tempFile}}" style=" width:{{code_w}}px;height:{{code_w}}px;" bindtap="Sharing"></image>
js代码
data:{
text: ‘链接’,
image: ‘图片’,
code_w: code_w,
tempFile:‘保存’,
}
//加载的时候生成[图片
onLoad: function (options) {
//我这边生成二维码方法是 调用QR code 生成
qrcode = new QRCode('canvas', {
// usingIn: ac,
text: ‘链接’,
// image: '/images/bg.jpg',//图片
width: code_w,//二维码 宽
height: code_w,//二维码 高
colorDark: "#1CA4FC",//交替颜色
colorLight: "white",//交替颜色
correctLevel: QRCode.CorrectLevel.H,
});
var that=this
wx.showLoading()//加载
//设置时间器
setTimeout(function () {
wx.hideLoading();
//将canvas转换成图片
wx.canvasToTempFilePath({
x: 0,
y: 0,
canvasId: 'canvas',//wxml中canvasid定义的id
success: function (res) {
console.log(res)
console.log('图片',res.tempFilePath)//生成的路径
var tempArr = []
tempArr.push(res.tempFilePath)
console.log(tempArr)
that.setData({
tempFile: tempArr//保存路径
})
},
fail: function (res) {
}
})
}, 1000)
点击图片跳转至新页面操作
进行保存和分享个朋友
//点击跳转 进行分享操作 只能在真机调试里面显示 分享操作和保存图片操作
Sharing:function(event){
console.log(this.data.tempFile)
var path=this.data.tempFile//获取路径
console.log(path)
wx.previewImage({
urls: path,//路径
showmenu:true,//是否显示菜单
current:path,//显示图片
success:function(res){
console.log(res)
},fail:function(res){
console.log(res)
}
})
}
微信文档 wx.previewImage相关参数.
以上就是绘画转图片 和分享操作