Page({ data: { image1: '', baseImg: '', // base64没有data:image/jpg;base64, image: 'cloud://develop-3gb3s6m1d5806159.6465-develop-3gb3s6m1d5806159-1304559061/images/tool/cat_change/add.png', // 这里图片需要换 }, chooseImage() { var that = this; wx.showActionSheet({ itemList: ['从相册中选择', '拍照'], itemColor: "#FAD143", success: function (res) { if (!res.cancel) { wx.showLoading({ title: '正在读取...', }) // wx.showToast({ // title: '正在读取...', // icon: 'loading' // }) if (res.tapIndex == 0) { that.chooseWxImage1('album', 1) } else if (res.tapIndex == 1) { that.chooseWxImage1('camera', 1) } } } }) }, chooseWxImage1(type, imglng) { var that = this; console.log(imglng) wx.chooseImage({ count: imglng, // 最大图片数量 sizeType: ['original'], // ['original', 'compressed'], // compressed : 压缩图 sourceType: [type], success: function (res) { // that.setData({ // image: res.tempFilePaths // }) //以下为图片路径转base64位 //图片base64位 wx.getFileSystemManager().readFile({ filePath: res.tempFilePaths[0], //选择图片返回的相对路径 encoding: 'base64', //编码格式 success: (res) => { wx.showLoading({ title: '正在检查图片...', }) let baseImg = res.data let image = 'data:image/png;base64,' + res.data // console.log(baseImg) // 检查图片是不是动物,再判断是否为猫咪 wx.cloud.callFunction({ name: 'checkAnimal', data: { datas: { image: baseImg, } } }).then(res => { console.log(res) var checkName = res.result.result[0].name console.log(checkName.indexOf("猫")) if (!checkName || checkName.indexOf("猫") == -1) { wx.showToast({ title: '请添加有猫咪的照片!', icon: 'none' }) } else { that.setData({ image, baseImg }) } // that.setData({ // image: 'data:image/png;base64,' + res.result.image, // baseImg: res.result.image, // }) }).catch(err => { }).finally(() => { wx.hideLoading() }) } }) // } catch (err) { // console.log(err) // } console.log(res.tempFilePaths[0]) } }) wx.hideLoading() }, /** * 变卡通 */ changePic: function (e) { let that = this var baseImg = that.data.baseImg if (baseImg.length < 8) { wx.showToast({ title: '请先添加小猫照片噢~', icon: 'none' }) return } wx.showLoading({ title: '正在变身...', }) wx.cloud.callFunction({ name: 'catChange', data: { datas: { image: that.data.baseImg, } } }).then(res => { console.log(res) that.setData({ image: 'data:image/png;base64,' + res.result.image, baseImg: res.result.image, }) }).catch(err => { }).finally(() => { wx.hideLoading() }) }, savePic(e) { let that = this var baseImg = that.data.baseImg if (baseImg.length < 8) { wx.showToast({ title: '请先生成卡通猫咪~', icon: 'none' }) return } //保存图片 var save = wx.getFileSystemManager(); var number = Math.random(); save.writeFile({ filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png', data: baseImg, encoding: 'base64', success: res => { wx.saveImageToPhotosAlbum({ filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png', success: function (res) { wx.showToast({ title: '保存成功', }) }, fail: function (err) { console.log(err) } }) console.log(res) }, fail: err => { console.log(err) } }) }, /** * 页面接受参数 */ onLoad: function (options) {}, })
相关知识
【开源】【猫咪卡通变
机器人开源项目
开源h5游戏 宠物
安桌开源项目
推荐开源项目:DesktopPet
开源期刊OA=水刊?带你重新认识
2023XuperCore开源区块链创新赛
开源SCI=水刊?1W+的版面费到底值不值得?
【Flutter开源社区|每日一例】一个宠物领养的APP
miumiu猫咪卡包——宠物主题的时尚必备(用miumiu猫咪卡包)
网址: 【开源】【猫咪卡通变 https://m.mcbbbk.com/newsview750369.html
上一篇: 《欢天喜地七仙女》第2集 |
下一篇: 头像丨宠物头像丨可爱头像 |