小程序模板網(wǎng)

微信小程序使用相機

發(fā)布時間:2018-07-27 11:56 所屬欄目:小程序開發(fā)教程

 

 
 
 

 

 

						
  1. <view class="page-body">
  2. <view class="page-body-wrapper">
  3. <camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
  4. <view class="btn-area">
  5. <button type="primary" bindtap="takePhoto">拍照</button>
  6. </view>
  7. <view class="btn-area">
  8. <button type="primary" bindtap="startRecord">開始錄像</button>
  9. </view>
  10. <view class="btn-area">
  11. <button type="primary" bindtap="stopRecord">結(jié)束錄像</button>
  12. </view>
  13. <view class="preview-tips">預(yù)覽</view>
  14. <image wx:if="{{src}}" mode="widthFix" src="{{src}}"></image>
  15. <video wx:if="{{videoSrc}}" class="video" src="{{videoSrc}}"></video>
  16. </view>
  17. </view>
 

						
  1. onLoad() {
  2. this.ctx = wx.createCameraContext()
  3. },
  4. takePhoto() {
  5. this.ctx.takePhoto({
  6. quality: 'high',
  7. success: (res) => {
  8. this.setData({
  9. src: res.tempImagePath
  10. })
  11. }
  12. })
  13. },
  14. startRecord() {
  15. this.ctx.startRecord({
  16. success: (res) => {
  17. console.log('startRecord')
  18. }
  19. })
  20. },
  21. stopRecord() {
  22. this.ctx.stopRecord({
  23. success: (res) => {
  24. this.setData({
  25. src: res.tempThumbPath,
  26. videoSrc: res.tempVideoPath
  27. })
  28. }
  29. })
  30. },
  31. error(e) {
  32. console.log(e.detail)
  33. }
 

						
  1. /* pages/one/one.wxss */
  2. .preview-tips {
  3. margin: 20rpx 0;
  4. }
  5.  
  6. .video {
  7. margin: 50px auto;
  8. width: 100%;
  9. height: 300px;
  10. }
 


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://22321a.com/wxmini/doc/course/24663.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢