取景框图片 小程序_微信小程序实现身份证取景框拍摄

这篇教程详细介绍了如何使用微信小程序实现身份证的取景框拍摄功能。通过设置CSS样式创建相机视图和身份证框,并提供了拍照、取消和保存图片的交互操作。示例代码包括wxml、wxss和js部分,帮助开发者实现这一实用功能。
摘要由CSDN通过智能技术生成

本文实例为大家分享了微信小程序实现身份证取景框拍摄的具体代码,供大家参考,具体内容如下

wxml

wxss

.camera_box {

height: 100vh; width: 100vw;

position: relative;

}

.camera {

height: 85vh; width: 100vw;

z-index: 1;

}

.id_m {

height: 85vh; width: 100vw;

z-index: 999;

background: rgba(0, 0, 0, 0.1);

display: flex;

position: absolute;

}

.id_m .img {

width: 550rpx;

height: 900rpx;

display: block;

position: absolute;

left: 0; right: 0; margin: auto auto;

top: 0; bottom: 0;

}

.id_m .tips_txt {

transform:rotate(90deg);

}

.camera_box .action {

height: 15vh;

position: relative;

display: flex;

justify-content: space-around;

align-items: center;

}

.camera_box .takeBtn {

height: 120rpx; width: 120rpx; border-radius: 50%;

font-size: 24rpx;

background: url('/uploads/allimg/200909/1123123123123e3241.png') no-repeat center;

background-size: contain;

border: none;

}

.camera_box .cancelBtn {

font-size: 24rpx;

height: 120rpx; width: 120rpx; border-radius: 50%;

background: url('/uploads/allimg/200909/12311123342312231.png') no-repeat center;

background-size: contain;

border: none;

}

.camera_box .saveImg {

background: url('/uploads/allimg/200909/1232123434231231231.png') no-repeat center;

font-size: 24rpx;

height: 120rpx; width: 120rpx; border-radius: 50%;

background-size: contain;

border: none;

}

.camera_box .takeBtn::after {

border: none;

}

.camera_img {

height: 85vh; width: 100%;

}

js

Page({

/**

* 页面的初始数据

*/

data: {

src: '',

show: false

},

cancelBtn () {

this.setData({show: false})

},

saveImg () {

wx.showModal({

title: '图片地址',

content: this.data.src,

})

},

takePhoto() {

const ctx = wx.createCameraContext()

const listener = ctx.onCameraFrame((frame) => {

console.log(frame)

})

ctx.takePhoto({

quality: 'high',

success: (res) => {

console.log(res)

this.setData({

src: res.tempImagePath,

show: true

})

listener.stop({

success: (res) => {

console.log(res)

},

fail: (err) =>{

console.log(err)

}

})

},

fail: (err) => {

console.log(err)

}

})

},

error(e) {

console.log(e.detail)

},

/**

* 生命周期函数--监听页面加载

*/

onLoad: function (options) {

},

/**

* 生命周期函数--监听页面初次渲染完成

*/

onReady: function () {

},

/**

* 生命周期函数--监听页面显示

*/

onShow: function () {

},

/**

* 生命周期函数--监听页面隐藏

*/

onHide: function () {

},

/**

* 生命周期函数--监听页面卸载

*/

onUnload: function () {

},

/**

* 页面相关事件处理函数--监听用户下拉动作

*/

onPullDownRefresh: function () {

},

/**

* 页面上拉触底事件的处理函数

*/

onReachBottom: function () {

},

/**

* 用户点击右上角分享

*/

onShareAppMessage: function () {

}

})

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持站圈网。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值