您当前的位置: 首页 > 解决方案

微信小程序使用相机

  • 作者: admin
  • 发布于 2018-07-27 13:54:02
  • 来源:  
  • 栏目:解决方案

导语: <view class="page-body"> <view class="page-body-wrapper"> <camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;">

 

  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">结束录像</button>
  12. </view>
  13. <view class="preview-tips">预览</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. }



温馨提示:这篇文章没有解决您的问题?欢迎添加微信:18948083295,有微信小程序专业人员,保证有问必答。转载本站文章请注明转自http://www.okeydown.com/(微信小程序网)。

  • 微信扫描二维码关注官方微信
  • ▲长按图片识别二维码
关注我们

微信小程序官方微信

栏目最新
栏目推荐
返回顶部