微信拍照翻译, 使用小程序拍照翻译API功能
今天一位粉丝问了一个问题,关于小程序本地相册选择图片或相机拍照底部弹框功能,小程序根据文档来写,为什么没有底部弹框,点击按钮就直接打开了手机相册了。看了一下不是他代码的原因,也不是什么bug,而是只写了部分功能。今天把这两个功能连起来说一说。
老规矩,放上小程序官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/wx.chooseImage.html
效果如下:点击按钮,选择图片进行替换,或者拍到一张照片,进行更换。微信拍照翻译, 使用小程序拍照翻译API功能代码:
微信拍照翻译, 使用小程序拍照翻译API功能wxml:
点击更换图片 wxss:.btn { margin: 140rpx;} .img { width: 100%; height: 480rpx;}微信拍照翻译, 使用小程序拍照翻译API功能jsPage({ data: { img: '../../images/1.jpg' }, onLoad: function() {}, chooseWxImage: function(type) { var that = this; wx.chooseImage({ sizeType: ['original', 'compressed'], sourceType: [type], success: function(res) { console.log(res); that.setData({ // tempFilePath可以作为img标签的src属性显示图片 img: res.tempFilePaths[0], }) } }) }, chooseimage: function() { var that = this; wx.showActionSheet({ itemList: ['从相册中选择', '拍照'], itemColor: "#a3a2a2", success: function(res) { if (!res.cancel) { if (res.tapIndex == 0) { that.chooseWxImage('album') } else if (res.tapIndex == 1) { that.chooseWxImage('camera') } } } }) },})
老规矩,放上小程序官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/wx.chooseImage.html
官网里面的代码,使用chooseImage即可,count表示最多可以选择的图片张数, sizeType表示所选的图片的尺寸sourceType表示选择图片的来源,详情可以仔细阅读一下文档。
效果如下:点击按钮,选择图片进行替换,或者拍到一张照片,进行更换。微信拍照翻译, 使用小程序拍照翻译API功能代码:
微信拍照翻译, 使用小程序拍照翻译API功能wxml:
点击更换图片 wxss:.btn { margin: 140rpx;} .img { width: 100%; height: 480rpx;}微信拍照翻译, 使用小程序拍照翻译API功能jsPage({ data: { img: '../../images/1.jpg' }, onLoad: function() {}, chooseWxImage: function(type) { var that = this; wx.chooseImage({ sizeType: ['original', 'compressed'], sourceType: [type], success: function(res) { console.log(res); that.setData({ // tempFilePath可以作为img标签的src属性显示图片 img: res.tempFilePaths[0], }) } }) }, chooseimage: function() { var that = this; wx.showActionSheet({ itemList: ['从相册中选择', '拍照'], itemColor: "#a3a2a2", success: function(res) { if (!res.cancel) { if (res.tapIndex == 0) { that.chooseWxImage('album') } else if (res.tapIndex == 1) { that.chooseWxImage('camera') } } } }) },})
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

