123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- const app = getApp()
- let ctxWidth = '';
- let ctxHeight = '';
- let ctx = null;
- let canvaCtx=null;
- Page({
- data: {
-
- },
- changeText() {
- wx.getSystemInfo({
- success: res => {
- let convasX = res.screenWidth / 4;
- let convasY = res.screenHeight / 5;
- let canvasWidth = convasX * 3;
- let canvasHeight = convasY * 3;
- let convasXL = convasX / 2;
- ctxWidth = canvasWidth;
- ctxHeight = canvasHeight;
- this.setData({
- info: res,
- canvasWidth,
- canvasHeight,
- convasX,
- convasXL,
- convasY
- })
- }
- })
- },
- onLoad: function () {},
- onShow() {
- this.changeText()
- },
- takePhoto() {
- ctx = wx.createCameraContext();
- ctx.takePhoto({
- quality: 'high',
- success: (res) => {
- this.takeCanvas(res.tempImagePath)
- this.setData({
- baseImg: res.tempImagePath,
- isBaseImg: true,
- isCanvas:true
- })
- }
- })
- },
- takeCanvas(path) {
- wx.getImageInfo({
- src: path,
- success: imgInfo => {
- let {info} = this.data;
- let convasX = imgInfo.width / 4;
- let convasY = imgInfo.height / 5;
- let canvasWidth = convasX * 3;
- let canvasHeight = convasY * 3;
- let convasXL = convasX / 2;
-
- let prxHeight = info.windowHeight / imgInfo.height;
- let prxWidth = info.windowWidth / imgInfo.width;
-
- canvaCtx = wx.createCanvasContext("myCanvas");
- canvaCtx.drawImage(path,convasXL,(convasY-40),canvasWidth,canvasHeight,0,0,(parseInt(canvasWidth) * prxWidth),(parseInt(canvasHeight) * prxHeight));
- canvaCtx.draw(true, () => {
- wx.canvasToTempFilePath({
- fileType: "jpg",
- quality: 0.3,
- canvasId: "myCanvas",
- success: canvasToPath => {
- this.setData({
- isSuccess:true,
- isBaseImg: false,
- isCanvas:false,
- baseImg: canvasToPath.tempFilePath,
- srcCanvasPath: canvasToPath.tempFilePath
- })
- }
- })
-
-
-
-
-
-
-
-
-
-
-
-
- })
- }
- })
- },
- clearPhoto(){
- canvaCtx.clearRect(0,0,ctxWidth, ctxHeight)
- canvaCtx.draw()
- this.setData({
- srcCanvasPath:"",
- isCanvas:false,
- isSuccess:false,
- isBaseImg:false
- })
- },
- confirmBack(){
-
- }
- })
|