找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

微信小程序使用相机

作者:模板之家 2018-7-27 11:55 6218人关注

view class=page-body view class=page-body-wrapper camera device-position=back flash=off binderror=error style=width: 100%; height: 300px;/camera view class=btn-area button type=primary bindtap=takePho ...

 

 
 
 

 

 

						
  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. }
 


路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)