本文实例为大家分享了微信小程序实现身份证取景框拍摄的具体代码,供大家参考,具体内容如下
wxml
<view class="camera_box">
<camera class="camera" wx:if="{{!show}}" device-position="back" flash="off" binderror="error">
<cover-view class="id_m">
<cover-image class="img" src="/UploadFiles/2021-04-02/202099172501721.png">
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('https://cdn.ctoku.com/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('https://cdn.ctoku.com/12311123342312231.png') no-repeat center;
background-size: contain;
border: none;
}
.camera_box .saveImg {
background: url('https://cdn.ctoku.com/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 () {
}
})
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“微信小程序实现身份证取景框拍摄”评论...
更新动态
2025年10月31日
2025年10月31日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]