1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| var context = null; var isButtonDown = false; var arrx = []; var arry = []; var arrz = []; var canvasw = 0; var canvash = 0;
Page({ canvasIdErrorCallback: function (e) { console.error(e.detail.errMsg) },
canvasStart: function (event) { console.log("start", event.changedTouches[0]) isButtonDown = true; arrz.push(0); arrx.push(event.changedTouches[0].x); arry.push(event.changedTouches[0].y); console.log("") }, data: { src: "", img: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=578899140,1412678472&fm=27&gp=0.jpg", rpx: '' },
onLoad: function (options) { var that = this
context = wx.createCanvasContext('canvas'); context.beginPath() context.setStrokeStyle('#000000'); context.setLineWidth(4); context.setLineCap('round'); context.setLineJoin('round');
context.draw(); },
canvasMove: function (event) { var that = this if (isButtonDown) { arrz.push(1); console.log(event) arrx.push(event.changedTouches[0].x); arry.push(event.changedTouches[0].y); };
for (var i = 0; i < arrx.length; i++) { if (arrz[i] == 0) { context.moveTo(arrx[i], arry[i]) } else { context.lineTo(arrx[i], arry[i]) };
}; context.clearRect(0, 0, canvasw, canvash); context.setStrokeStyle('#000000'); context.setLineWidth(4); context.setLineCap('round'); context.setLineJoin('round'); context.stroke();
context.draw(false); },
clickMe: function () { wx.canvasToTempFilePath({ canvasId: 'canvas', fileType: 'jpg', success: function (res) { console.log(res) wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success(res) { console.log(res) wx.hideLoading(); wx.showToast({ title: '保存成功', });
}, fail() { wx.hideLoading() } }) } }) }, canvasEnd: function (event) { isButtonDown = false; }, cleardraw: function () {
arrx = []; arry = []; arrz = []; context.draw(false); } })
|