微信小程序canvas 证件照制作( 三 )
(function(f) {'use strict';/* istanbul ignore else */if (typeof exports === 'object' && exports != null &&typeof exports.nodeType !== 'number') {module.exports = f ();} else if (typeof define === 'function' && define.amd != null) {define ([], f);} else {var base64 = f ();var global = typeof self !== 'undefined' ? self : $.global;if (typeof global.btoa !== 'function') global.btoa = base64.btoa;if (typeof global.atob !== 'function') global.atob = base64.atob;}} (function() {'use strict';var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';function InvalidCharacterError(message) {this.message = message;}InvalidCharacterError.prototype = new Error ();InvalidCharacterError.prototype.name = 'InvalidCharacterError';// encoder// [https://gist.github.com/999166] by [https://github.com/nignag]function btoa(input) {var str = String (input);for (// initialize result and countervar block, charCode, idx = 0, map = chars, output = '';// if the next str index does not exist://change the mapping table to "="//check if d has no fractional digitsstr.charAt (idx | 0) || (map = '=', idx % 1);// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8output += map.charAt (63 & block >> 8 - idx % 1 * 8)) {charCode = str.charCodeAt (idx += 3 / 4);if (charCode > 0xFF) {throw new InvalidCharacterError ("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");}block = block << 8 | charCode;}return output;}// decoder// [https://gist.github.com/1020396] by [https://github.com/atk]function atob(input) {var str = (String (input)).replace (/[=]+$/, ''); // #31: ExtendScript bad parse of /=// if (str.length % 4 === 1) {//throw new InvalidCharacterError ("'atob' failed: The string to be decoded is not correctly encoded.");// }for (// initialize result and countersvar bc = 0, bs, buffer, idx = 0, output = '';// get next characterbuffer = str.charAt (idx++); // eslint-disable-line no-cond-assign// character found in table? initialize bit storage and add its ascii value;~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,// and if not first of each 4 characters,// convert the first 8 bits to one ascii characterbc++ % 4) ? output += String.fromCharCode (255 & bs >> (-2 * bc & 6)) : 0) {// try to find character in table (0-63, not found => -1)buffer = chars.indexOf (buffer);}return output;}return {btoa: btoa, atob: atob};}));
- 在源码中修改调用
const polyfill = require('../../../util/btoa.js');const {btoa, atob} = polyfill;
下载证件照到手机相册export const savePoster = (url) => {const that = thiswx.saveImageToPhotosAlbum({filePath: url,success: function() {wx.showToast({title: '保存成功',icon: 'none',duration: 1500});},fail(err) {if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {wx.showModal({title: '提示',content: '需要您授权保存相册',showCancel: false,success: modalSuccess => {wx.openSetting({success(settingdata) {if (settingdata.authSetting['scope.writePhotosAlbum']) {wx.saveImageToPhotosAlbum({filePath: url,success: function () {wx.showToast({title: '保存成功',icon: 'success',duration: 2000})},})} else {wx.showToast({title: '授权失败,请稍后重新获取',icon: 'none',duration: 1500});}}})}})}}})}
下面是利用canvas 做的小应用,欢迎大家扫描体验,并提出建议 。让我们共同进步
文章插图
[项目代码] https://gitee.com/eyes-star/txy-mp.git

文章插图
[项目代码] https://gitee.com/eyes-star/zjz-mp.git
经验总结扩展阅读
- 2022蚂蚁庄园8月16日答案最新
- 小米盒子4s pro评测_小米盒子4s pro怎么样
- 小米11ultra和小米11pro参数_参数配置详情对比
- 小度智能屏x10不插电源可以用吗?
- 小米11ultra怎么读取u盘_读取u盘方法教程
- iqoo8pro和小米11ultra区别对比_哪款更值得入手
- 北京市小客车指标中签查询 北京市小客车指标查询
- 聪明小三哄男人常说的30句话
- 男人听了会心疼小三的话 撩男朋友甜甜软软情话
- 高情商小三哄男人的话 男人很享受女人对他撒娇的文案