⼩程序拍照截取指定区域图⽚(话不多说,直接上代码)效果图
wxml
<camera if='{{isShowCamera}}' class="camera-box" devic-position="width" flash="off" style='width:{{windowWidth}}px; height:{{windowHeight}}px;'> <cover-view class='camerabgImage'>
<cover-view class="active">
<cover-image class="active-image" src="dekoa/blog/2020/12/0716073342969601272.png"></cover-image>
<cover-view class="text">请将VIN码放⼊框中,点击拍照进⾏识别</cover-view>
<cover-view class="btn" bindtap="takePhotoAction">
<cover-view class="button"></cover-view>
</cover-view>
</cover-view>
</cover-view>
</camera>
<canvas if='{{isShowImage}}' canvas-id="image-canvas"
style='width:{{windowWidth}}px; height:{{windowHeight}}px;'></canvas>
wxss
.camera-box{
width: 100vw;
height: 100vh
}
.camera-box .camerabgImage{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0
}
.camera-box .camerabgImage .active{ position: absolute;
top: 400rpx;
left: 36rpx;
right: 36rpx
}
.camera-box .camerabgImage .active-image{ display: block;
width: 680rpx;
height: 280rpx
}
.camera-box .camerabgImage .text{
text-align: center;
margin-top: 56rpx;
margin-bottom: 240rpx;
font-size: 28rpx;
font-weight: 400;
color: #D9D9D9;
line-height: 40rpx
}
.
camera-box .camerabgImage .btn{ width: 110rpx;
height: 110rpx;
border-radius: 50%;
background: #fff;
border: 6rpx solid#fff;
margin: 0 auto
}
.camera-box .camerabgImage .btn .button{ width: 102rpx;
height: 102rpx;
border-radius: 50%;
border: 4rpx solid#000
}
js
// 获取全局应⽤程序实例对象
// const app = getApp();
// 创建页⾯实例对象
Page({
// 页⾯的初始数据
data:{
isShowCamera:false,
isShowImage:true,
isShowImage:true,
image:'',
windowWidth:'',
windowHeight:''
},
onLoad(){
< = wx.createCameraContext()
let{windowWidth, windowHeight}= wx.getSystemInfoSync()
this.setData({windowWidth, windowHeight})
},
onShow:function(){
var that =this
wx.authorize({
scope:'scope.camera',
success:function(res){
that.setData({
isShowCamera:true,
})
代码转换},
fail:function(res){
console.log(""+ res);
wx.showModal({
title:'请求授权您的摄像头',
content:'如需正常使⽤此⼩程序功能,请您按确定并在设置页⾯授权⽤户信息', confirmText:'确定',
success: res =>{
firm){
wx.openSetting({
success:function(res){
console.log('成功');
console.log(res);
if(res.authSetting['scope.camera']){//设置允许获取摄像头
console.log('设置允许获取摄像头')
wx.showToast({
title:'授权成功',
icon:'success',
duration:1000
})
that.setData({
isShowCamera:true,
})
}else{//不允许
wx.showToast({
title:'授权失败',
icon:'none',
duration:1000
})
wx.navigateBack({delta:1})
}
}
})
}else{//取消
wx.showToast({
title:'授权失败',
icon:'none',
duration:1000
})
wx.navigateBack({delta:1})
}
}
})
}
})
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论