| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- var _request = require('../../../utils/request.js')
- var canvas = {}
- var width = 0
- var height = 0
- var ctx
- var img
- var imgInfo = {}
- var touchX = 0
- var touchY = 0
- var ix = 50
- var iy = 200
- Page({
- data: {
- },
- onLoad: function (options) {
- var info = wx.getSystemInfoSync()
- console.log(info)
- width = info.windowWidth
- height = info.windowHeight
- ctx = wx.createCanvasContext('myCanvas')
- this.draw()
- ctx.draw()
- },
- draw: function () {
- ctx.save()
- ctx.setFillStyle('#0b0b0b')
- ctx.setFontSize(this.dpi(28))
- ctx.fillText('明明什么都没有做', this.dpi(75), this.dpi(42))
- ctx.setFontSize(this.dpi(26))
- ctx.fillText('就已经', this.dpi(35), this.dpi(120))
- ctx.fillText('了', this.dpi(275), this.dpi(120))
- ctx.restore()
- },
- dpi: function (val) {
- return val * width / 375
- },
- ming: function () {
- wx.navigateTo({
- url: '/pages/start/start'
- })
- },
- shang: function () {
- var that = this
- wx.chooseImage({
- count: 1,
- success: function (val) {
- console.log(val)
- img = val.tempFilePaths[0]
- that.chooseImage()
- }
- })
- },
- chooseImage: function (val) {
- var that = this
- wx.getImageInfo({
- src: img,
- success: function (res) {
- console.log(res)
- imgInfo = res
- that.drawImage()
- }
- })
- // ctx.drawImage(sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
- },
- drawImage: function () {
- var w = 275
- var h = w * imgInfo.height / imgInfo.width
- console.log(h)
- console.log(img)
- console.log(String(h))
- ctx.drawImage(String(img), this.dpi(ix), this.dpi(iy), this.dpi(w), this.dpi(h))
- this.draw()
- ctx.draw()
- },
- save: function () {
- var that = this
- wx.canvasToTempFilePath({
- destWidth: width * 2,
- destHeight: height * 2,
- canvasId: 'myCanvas',
- fileType: 'jpg',
- success: function (res) {
- that.saveImage(res.tempFilePath)
- }
- })
- },
- saveImage: function (val) {
- wx.saveImageToPhotosAlbum({
- filePath: val,
- success(res) {
- wx.showToast({
- title: '已保存相册',
- icon: 'success',
- duration: 2000
- })
- }
- })
- },
- move: function (res) {
- console.log(res)
- if (img) {
- if (res.touches.length === 1) {
- var x = res.touches[0].x - touchX
- var y = res.touches[0].y - touchY
- ix = ix + x
- iy = iy + y
- touchX = res.touches[0].x
- touchY = res.touches[0].y
- this.drawImage()
- }
- }
- },
- start: function (val) {
- touchX = val.changedTouches[0].x
- touchY = val.changedTouches[0].y
- },
- onShareAppMessage: function (val) {
- if (val.from === 'button') {
- }
- return {
- title: '"明明什么都没有做"壁纸生成工具',
- path: '/pages/activity/screen/screen',
- imageUrl: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/share/mingming.jpg',
- success: function(res) {
- },
- fail: function(res) {
- }
- }
- },
- })
|