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

719
2020/12/16 14:12:10
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

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

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

}

})

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 百度小程序的优势有哪些