W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
基礎庫 1.6.0 開始支持,低版本需做兼容處理。
系統(tǒng)相機。
需要用戶授權 scope.camera
屬性名 | 類型 | 默認值 | 說明 |
---|---|---|---|
device-position | String | back | 前置或后置,值為front, back |
flash | String | auto | 閃光燈,值為auto, on, off |
bindstop | EventHandle | 攝像頭在非正常終止時觸發(fā),如退出后臺等情況 | |
binderror | EventHandle | 用戶不允許使用攝像頭時觸發(fā) |
相關api:wx.createCameraContext
示例:
<!-- camera.wxml -->
<camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<button type="primary" bindtap="takePhoto">拍照</button>
<view>預覽</view>
<image mode="widthFix" src="{{src}}"></image>
// camera.js
Page({
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
}
})
},
error(e) {
console.log(e.detail)
}
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: