最近寫識別行駛證功能,點擊拍照把指定區域截取,生成圖片功能。
系統相機。該組件是原生組件,使用時請注意相關限制。 掃碼二維碼功能,需升級微信客戶端至6.7.3。
微信小程序Camera相機地址
我們看下效果:

1、首先生成一個CanvasContext:
/** * 生命周期函數--監聽頁面加載 */ onLoad: function(options) { requireJs.adaptionIphoneX(this); this.ctx = wx.createCameraContext() },2、相機的 wxml樣式

<camera wx:if='{{isShowCamera}}' device - position="width" flash="off" style="width:{{windowWidth}}px; height:{{windowHeight}}px;"> <cover-view class='camerabgImage-view'> <cover-image class='bgImage' src='{{isIphoneX==true?"../../myImage/vehicle/biankuang_x.png":"../../myImage/vehicle/biankuang.png"}}'> </cover-image> <cover-view class='cameratop-view1'>中華人民共和國機動車行駛證</cover-view> <cover-view class='cameratop-view2'>(行駛證主頁)</cover-view> <cover-view class='cameracenter-view' style='top:{{isIphoneX==true?"52%":"62%"}}'>請對準左下角發證機關印章</cover-view> <!-- 拍照按鈕 --> <cover-view class='camerabotton-view' style='bottom:{{isIphoneX==true?"75px":"0px"}}'> <cover-image class='cancelphoto' src='../../myImage/vehicle/quxiao.png' bindtap='cancelPhotoAction'></cover-image> <cover-image class='takephoto' src='../../myImage/vehicle/paizhao.png' bindtap='takePhotoAction'></cover-image> <cover-view class='skipphoto' bindtap='skipphotoAction'>{{skipphotoStatus==1?"跳過":""}} </cover-view> </cover-view> </cover-view> </camera> <canvas wx:if='{{isShowImage}}' canvas-id="image-canvas" style='width:{{windowWidth}}px; height:{{windowHeight}}px;'></canvas>3、相機的 wxss樣式
.camerabgImage-view{ height: 100%; width: 100%; position:absolute;}.bgImage{ width: 100%; height: 100%; position: absolute;} .cameratop-view1{ margin-top: 174rpx;}.cameratop-view2{ margin-top: 220rpx;}.cameratop-view1, .cameratop-view2{ width: 100%; display: flex; justify-content: center; position: absolute; font-family: PingFangSC-Medium; font-size: 36rpx; color: #FFFFFF; letter-spacing: 0; text-align: center;} .cameracenter-view{ height: 44rpx; width: 100%; position: absolute; font-family: PingFangSC-Medium; font-size: 32rpx; color: #FFFFFF; letter-spacing: 0; text-align: center;} /* 底部 */.camerabotton-view{ height: 200rpx; width: 100%; position:absolute; display: flex; justify-content: space-around; align-items: center;}.cancelphoto{ width: 50rpx; height: 50rpx;}.takephoto{ width: 132rpx; height: 132rpx;}.skipphoto{ font-family: PingFangSC-Regular; font-size: 32rpx; color: #FFFFFF; letter-spacing: 0; text-align: center;}
新聞熱點
疑難解答