项目实训七,拍照签名并提取

微信通过拍照,提取签名信息,通过上景减下景得到纯白底色

js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    TabList: [
      {name: '1. 拍照'},
      {name: '2. 预览上传'}
    ],
    TabCur: 0,
    Snap: false,
    Preview: false,
    img: '',
    sourceKey: '',
    calImg: '',
    weight:50,
    imgList: [],
  },
  onLoad: function () {
    
  },
  upImg:function () {
      var that = this;
      if (that.data.imgList.length != 0) {
        that.setData({
          imgList: that.data.imgList.concat(that.data.calImg)
        })
      } else {
        that.setData({
          imgList: that.data.calImg
        })
      }
    
    let base64 = wx.getFileSystemManager().readFileSync(that.data.imgList, "base64");
    let img = `data:base64,${base64}`;
    console.log(base64);
    wx.request({
      url: app.globalData.globalReqUrl +'/api/sign/base64',
      data:{
        photo:base64,
      },
      method:'POST',
      header:{
        'content-type':'application/x-www-form-urlencoded',
        'token':app.globalData.token
      },
      success:function(res){
        console.log(res);
        let error = null;
        if(res.data.status!="200"){

          error = "系统错误 请稍后尝试"
         
      }
      if(res.data.status=="200"){

      
       
    }
        if(error !== null){
          wx.showToast({
            title: error,
            icon:'none',
            duration:2000
          })
         
        }else{
          
            wx.showToast({
            title:'上传成功',
            icon:'success',
            duration:1000,
            success:function(){
              setTimeout(function(){
                wx.navigateBack({
                  delta: 2,
                })
            },1000);
            }
          })    
       
        }
        
      },
      fail:function(res){
        console.log(res);
      
      }
    })
  
    
    
  }
  ,
  NumSteps() {
    this.setData({
      TabCur: this.data.TabCur == this.data.TabList.length - 1 ? 0 : this.data.TabCur + 1
    })
  },
  Navigate(e) {
    var target = e.currentTarget.dataset.index;
    if (target < this.data.TabCur){
      this.setData({
        TabCur: target
      })
    }
  },
  OpenCamera() {
    this.setData({
      Snap: true
    })
  },

  Cancel() {
    this.setData({ 
      Preview: false 
    })
  },
  SaveImg() {
    this.setData({
      Snap: false,
      Preview: false
    })
    this.RemoveBackground();
    this.NumSteps();
  },
  TakePhoto() {
    const ctx = wx.createCameraContext()
    const listener = ctx.onCameraFrame((frame) => {
      console.log(frame)
    })
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        console.log(res)
        this.setData({
          img: res.tempImagePath,
          Preview: true
        })
        listener.stop({
          success: (res) => {
            console.log(res)
          },
          fail: (err) => {
            console.log(err)
          }
        })
      },
      fail: (err) => {
        console.log(err)
      }
    })
  },

  TextChange(e) {
    this.setData({
      sourceKey: e.detail.value
    })
  },
  WeightChange(e) {
    this.setData({
      calImg: '',
      weight: e.detail.value
    })
    this.RemoveBackground();
  },
  WeightChanging(e) {

  },
  

  RemoveBackground(){
    const ctx = wx.createCanvasContext("myCanvas");
    var that = this;
    wx.getImageInfo({ 
      src: this.data.img, 
      success: function (res) { 
        console.log(res)
        ctx.drawImage(that.data.img, 0, 0, res.width, (res.width / 1080) * 960, 0, 0, 1080, 960);
        ctx.draw(false, () => {
          wx.canvasGetImageData({
            canvasId: "myCanvas",
            x: 240,
            y: 221,
            width: 600,
            height: 600,
            success: (res) => {
              console.log(res)
              var length = 600 * 300 * 4;
              var calData = new Uint8ClampedArray(length)
              var weight = that.data.weight / 50
              for(var i = 0; i < length; i++){
                calData[i] = (i % 4 === 3 ? 255 : (255 - (res.data[i + length] - res.data[i])) * 2 - (188 * weight));
              }
              wx.canvasPutImageData({
                canvasId: "myCanvas2",
                data: calData,
                x: 0,
                y: 0,
                width: 600,
                height: 300,
                success: (res) => {
                  console.log(res)
                  wx.canvasToTempFilePath({
                    width: 600,
                    height: 300,
                    canvasId: "myCanvas2",
                    success: function(res) {
                      console.log(res)
                      that.setData({
                        calImg: res.tempFilePath,
                      })
                    }
                  });
                },
                fail: res => {
                  console.log(res)
                },
              })
            },
            fail: res => {
              console.log(res)
            },
          })
        })
      } 
    })  
  }
})

wxml


<view class="bg-white padding">
  <view class="cu-steps">
    <view class="cu-item {{index > TabCur?'':'text-red'}}" bindtap="Navigate" data-index="{{index}}" wx:for="{{TabList}}" wx:key="index">
      <text class="cuIcon-{{index > TabCur ? 'title' : 'roundcheckfill'}}" data-index="{{index + 1}}"></text> {{item.name}}
    </view>
  </view>
</view>

<block wx:if="{{TabCur==0}}">
  <block wx:if="{{!Snap}}">
    <view class="bg-white margin-top padding">
      <view class="margin-bottom">
        <text>Step 1. 拍照</text>
      </view>
      <view class="image flex justify-center">
        <image src="/images/upload_signature/lead2-1.png" mode="widthFix" style="width:70%"></image>
      </view>
      <view class="margin-top">
        <text>将签名居中置于上半绿色方框中,文字底线需要和红色基准线对齐;</text>
      </view>
      <view class="margin-top">
        <text>为保证最佳的识别效果,</text>
        <text style="font-weight: bold">绿色方框内不能含有阴影;下半绿色方框是对照区,光线需和上半保持一致。</text>
      </view>
    </view>
    <view class="padding flex flex-direction">
      <button bindtap="OpenCamera" class="lg" style="width:100%">开始拍照</button>
    </view>
  </block>
  <block wx:if="{{Snap}}">
    <view class="camera_box">
      <camera class="camera" wx:if="{{!Preview}}" device-position="back" flash="off" binderror="error">
        <cover-view>
          <cover-image src="/images/upload_signature/cover.png"></cover-image>
        </cover-view>
      </camera>
      <image class="camera_preview" src="/images/upload_signature/cover.png" wx:if="{{Preview}}" mode="widthFix"></image>
      <image class="camera_img" src="{{img}}" wx:if="{{Preview}}" mode="widthFix"></image>
      <view class="action">
        <view class="photo_btn" bindtap="TakePhoto" wx:if="{{!Preview}}">
          <image src="/images/camera/snap.png" class="photo_btn"></image>
        </view>
        <view class="photo_btn" bindtap="Cancel" wx:if="{{Preview}}">
          <image src="/images/camera/cancel.png" class="photo_btn"></image>
        </view>
        <view class="photo_btn" bindtap="SaveImg" wx:if="{{Preview}}">
          <image src="/images/camera/confirm.png" class="photo_btn"></image>
        </view>
      </view>
    </view>
  </block>
</block>

<block wx:if="{{TabCur==1}}">
  <form>
    <view class="bg-white margin-top padding">
      <text>Step 2. 预览上传</text>
    </view>

    <view class="bg-white padding">
      <view class="flex justify-center">
        <text>拖动滑条,直到清晰为止</text>
      </view>
      <view class="flex justify-center">
        <slider style="width:100%" value="{{weight}}" bindchange="WeightChange" bindchanging="WeightChanging" min="0" max="100" activeColor='#0081FF' backgroundColor='#CCCCCC' block-size='12' block-color='#A10606' step="1"/>
      </view>
      <view class="image flex margin-bottom justify-center">
        <image src="{{calImg}}" mode="widthFix" wx:if="{{calImg}}" style="width:70%; max-height: 300px"></image>
        <view class="padding margin" wx:if="{{!calImg}}">
          <text>正在生成签名,请稍等...</text>
        </view>
      </view>
      <view class="flex justify-center">
        <text>您拍摄的签名</text>
      </view>
    </view>
    <view class="padding flex flex-direction">
      <button class="cu-btn bg-green lg" bindtap="upImg" style="width:100%">提交</button>
    </view>
  </form>
</block>

<view style='width:0px; height:0px; overflow:hidden; transform:scale(0,0)'>
  <canvas class="canvas" canvas-id="myCanvas"></canvas>
  <canvas class="canvas2" canvas-id="myCanvas2"></canvas>
</view>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
SSM项目在线商城是一种基于Spring + SpringMVC + MyBatis框架的互联网应用设计与开发项目。该项目的目标是构建一个功能完善的在线商城平台,实现用户注册、登录、商品浏览、购物车、订单管理等功能,提供便捷的购物体验。 在项目实训中,我们需要进行一系列的工作来完成这个项目。首先,我们需要进行需求分析,明确项目的功能和业务需求。然后,设计数据库,确定需要的表结构和字段。接下来,我们会搭建开发环境,包括安装JDK、配置Tomcat服务器等。同时,我们会使用Spring框架进行依赖注入和控制反转,使用SpringMVC框架完成请求的分发和处理,使用MyBatis框架完成数据库的操作,以保证项目的高效性和易维护性。 在开发过程中,我们会采用敏捷开发的方式,将整个项目分解为多个子任务,并按照优先级进行排列。每个子任务的开发都有相应的评估时间和实际开发时间,确保项目的开发进度和质量。在开发过程中,我们会使用版本控制工具,保留每个开发阶段的代码版本,方便后期回溯和维护。 同时,在项目实训中,我们也会进行测试工作。包括单元测试、集成测试和系统测试等,以保证项目的质量和稳定性。在测试阶段,我们会充分利用Mockito等工具进行接口的模拟和自动化测试,以提高测试效率和准确性。 最后,在项目实训中,我们还会进行项目的部署和上线工作。我们会将项目部署到服务器上,并进行性能测试和安全性测试,确保项目能够在实际环境中正常运行。同时,我们还会进行项目的维护和优化工作,及时修复bug,对系统进行性能优化,保持系统的稳定性。 通过这个SSM项目在线商城实训,我们能够全面学习和掌握SSM框架的应用和开发技术,提高自己的实际开发能力,并深入理解互联网应用的设计和开发过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值