温馨提示×

怎么设置小程序页面使用相机

小新
122
2020-12-16 14:12:10
栏目: 云计算

怎么设置小程序页面使用相机

设置小程序页面使用相机的案例:

在对应的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>

在对应的js文件中添加以下代码:

// pages/headline/headline.js

Page({

takePhoto(){

   const ctx=wx.createCameraContext()

   ctx.takePhoto({

     quality:'high',

     success:(res)=>{

       this.set.Data({

         src:res.tempImagePath

       })

     }

   })

},

error(e){

   console.log(e.detail)

}

})

0