wx.chooseImage的相机模式的bug
发布于 5 年前 作者 qiangdu 11649 次浏览 来自 问答

需求:

       通过点击上传照片按钮(提供两种模式:1、从相册获取图片;2、拍照获取图片),实现获取照片后,照片以及照片的文字说明(也就是代码中的userInfo数据)能够显示在小程序页面上。

问题:

       从相册获取图片的方式,是可以实现图片和文字展示在页面上的,但是拍照获取图片的方式,不能实现 上述效果(偶尔可以显示),数据是采用setData刷新的,页面也绑定了userInfo数据,现在不知道为什么拍照的方式出现的问题。

测试手机:iphone 6plus

核心代码:

  index.js

Page({

   data: {

       motto: ‘上传靓照’,

       userInfo: {}

   },

//事件处理函数

uploadImage: function() {

   var that = this

   wx.chooseImage({

    success: function(res) {

       var tempFilePaths = res.tempFilePaths

       console.log(res);

       wx.showToast({

           title: ‘鉴定中,请稍候’,

           icon: ‘loading’,

           duration: 2000

       })

       that.setData({

           userInfo: {

           //填充人脸识别界面的图片

           imageUrl: tempFilePaths[0],

           tips: ‘人脸识别中…’

           }

       })

   }

})

},

onLoad: function () {

   console.log(‘onLoad’)

}

})

index.wxml

<view class=“container”>

   <view class=“userinfo”>

       <image class=“userinfo-avatar” mode=“aspectFit” src="{{userInfo.imageUrl}}" background-size=“cover”>image>

   <text class=“userinfo-tips”>{{userInfo.tips}}text>

   view>

   <view class=“usermotto”>

       <button class=“button” type=“primary” bindtap=“uploadImage”>{{motto}}button>

   view>

view>

index.wxss

/**index.wxss**/

.userinfo {

display: flex;

flex-direction: column;

align-items: center;

}

.userinfo-avatar {

max-width: 400rpx;

max-height: 400px;

margin: 20rpx;

}

.userinfo-tips {

color: #aaa;

}

.usermotto {

position:fixed;

bottom: 20px;

}

.button{

background:#00e5ff !important;

}

效果图:

1、选择拍照的方式

2、从相册框里选择图片,可以显示图片信息和文字信息

3、用相机拍照,显示不出图片信息和文字信息

1 回复

急求呀,求大佬告知,以上代码可直接运行

回到顶部