本文实例为大家分享了微信小程序实现身份证取景框拍摄的具体代码,供大家参考,具体内容如下
wxml
1
2
3
4
5
6
7
8
9
10
11
12
13
|
< 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 = "//img.jbzj.com/file_images/article/202009/202099172501721.png" ></ cover-image > </ cover-view > </ camera > < image class = "camera_img" src = "{{src}}" wx:if = "{{show}}" ></ image > < view class = "action" > < button class = "takeBtn" type = "primary" bindtap = "takePhoto" wx:if = "{{!show}}" ></ button > < button class = "saveImg" type = "primary" bindtap = "saveImg" wx:if = "{{show}}" ></ button > < button class = "cancelBtn" wx:if = "{{show}}" type = "primary" bindtap = "cancelBtn" ></ button > </ view > </ view > |
wxss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
.camera_box { height : 100 vh; width : 100 vw; position : relative ; } .camera { height : 85 vh; width : 100 vw; z-index : 1 ; } .id_m { height : 85 vh; width : 100 vw; z-index : 999 ; background : rgba( 0 , 0 , 0 , 0.1 ); display : flex; position : absolute ; } .id_m .img { width : 550 rpx; height : 900 rpx; display : block ; position : absolute ; left : 0 ; right : 0 ; margin : auto auto ; top : 0 ; bottom : 0 ; } .id_m .tips_txt { transform:rotate( 90 deg); } .camera_box .action { height : 15 vh; position : relative ; display : flex; justify- content : space-around; align-items: center ; } .camera_box .takeBtn { height : 120 rpx; width : 120 rpx; border-radius: 50% ; font-size : 24 rpx; background : url ( 'https://cdn.ctoku.com/1123123123123e3241.png' ) no-repeat center ; background- size : contain; border : none ; } .camera_box .cancelBtn { font-size : 24 rpx; height : 120 rpx; width : 120 rpx; 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 : 24 rpx; height : 120 rpx; width : 120 rpx; border-radius: 50% ; background- size : contain; border : none ; } .camera_box .takeBtn::after { border : none ; } .camera_img { height : 85 vh; width : 100% ; } |
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
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 () { } }) |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_43447509/article/details/108244557