W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
基礎(chǔ)庫 1.6.0 開始支持,低版本需做兼容處理。
系統(tǒng)相機(jī)。
需要用戶授權(quán) scope.camera
屬性名 | 類型 | 默認(rèn)值 | 說明 |
---|---|---|---|
device-position | String | back | 前置或后置,值為front, back |
flash | String | auto | 閃光燈,值為auto, on, off |
bindstop | EventHandle | 攝像頭在非正常終止時(shí)觸發(fā),如退出后臺(tái)等情況 | |
binderror | EventHandle | 用戶不允許使用攝像頭時(shí)觸發(fā) |
相關(guān)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>預(yù)覽</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號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: