小程序之自定义拍照

小程序之自定义拍照

  1. 首先预览一下效果图,是否是大家想要的效果图

    在这里插入图片描述

  2. 实现功能主要用了哪些内容

    camera:系统相机
    cover-view:覆盖在原生组件之上的文本视图。

  3. 视图代码

    wxml
    <view class="waper flex-align-center">
      <view class="noticeTXT">请将身份证正面放入框内</view>
      <camera mode="normal" device-position="back" flash="auto" binderror="error" style="width: 90%; height: 250px;">
        <cover-view class="controls">
            <cover-image class="img" src="/images/border.png" style="width:100%; height:250px;"/>
        </cover-view>
      </camera>
    </view>
    <view class="takePhoto btn bg-brown" bindtap="takePhoto">拍照</view>
    
    wxss
    waper{
        width: 100%;
        height: 60vh;
        align-items: center;
        flex-direction: column;
    }
    .controls {
        position: relative;
        top: 0;
        display: flex;
    }
    
    .noticeTXT {
        text-align: center;
        margin-bottom: 100rpx;
    }
    
    .takePhoto{
        width: 90%;
        margin: 0 auto
    }
    
    .flex-align-center {
      display: flex;
      flex-direction: row;
      justify-content: center;
    }
    
    .btn {
      border-radius: 90rpx;
      padding: 15rpx 25rpx;
      text-align: center;
    }
    
    .bg-brown {
      color: #fff;
      background: linear-gradient(153deg, rgba(225, 164, 70, 1) 0%, rgba(195, 144, 65, 1) 100%);
    }
    
    js
    Page({
      data:{
        img:''
      },
      //拍照
      takePhoto() {
        const ctx = wx.createCameraContext()
        ctx.takePhoto({
          quality: 'high',
          success: (res) => {
          	//res.tempImagePath为拍取的相片
          	console.log('相片路径',res.tempImagePath)
          	this.setData({img:res.tempImagePath})
          }
        })
      }
    })
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值