當(dāng)前位置:首頁 > IT技術(shù) > 微信平臺(tái) > 正文

小程序調(diào)用系統(tǒng)照相機(jī)
2021-07-28 11:02:58

// pages/list/list.js
Page({
  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
      }
    })
  },
  error(e) {
    console.log(e.detail)
  }


})
<!--list.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>

調(diào)試需要使用真機(jī)調(diào)試,微信開發(fā)者工具不支持照相機(jī)調(diào)試。

開發(fā)文檔地址 https://developers.weixin.qq.com/miniprogram/dev/component/camera.html

?

本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >