二、点击按钮保存图片至相册如果调取用户授权访问相册,在用户拒绝后,安卓会出现无法再继续保存的问题,这边给出苹果和安卓都适用的方法,代码如下:搜索查看编辑修改首页UNITYNODEJSPYTHONAIGITPHPGOCEF3JAVAHTMLCSS搜索我家小花儿 这个屌丝很懒,什么也没留下! 关注作者热门标签jqueryHTMLCSSPHPASPPYTHONGOAICC++C#PHOTOSHOPUNITYiOSandroidvuexml爬虫SEOLINUXWINDOWSJAVAMFCCEF3CADNODEJSGITPyppeteerarticle热门文章1【机器学习】使用scikitLearn进行SVM支持向量机进行回归_sklearnsvm回归参数设置2多线程 Threading Multiprocessing(Python)3计算机网络 数据段、报文、IP数据报、数据包、MAC帧的区别;应用层、运输层、网络层、数据链路层、物理层的区别与功能;转发器、集线器、网桥、交换机、路由器、网关的功能与区别_网络中数据段是哪个层4SVN操作报错(乱码浠vn cleanup钬)_svn报错乱码5基于python3.6利用OpenCV遍历图片所有像素点且进行改变生成新图片_python opencv能根据像素生成图片吗6预训练模型的应用(pytorch)_预训练好的模型可以直接用于特征提取嘛7网页版滑动验证码+短信验证码(史上最全版)_哎呀,出错了,点击刷新再来一次8【React Native开发01】React Native从环境搭建到项目生成这一篇就够了_react native项目生成9使用nat123实现外网访问局域网中的linux主机10透明度测试(AlphaTest)和混合(Blend)的基础知识_alpha test当前位置: article > 正文 微信小程序保存图片(长按保存and点击保存)_微信小程序长按保存图片 作者:我家小花儿 | 2024-02-23 06:46:36 赞踩微信小程序长按保存图片 一、长按图片保存 只需要image标签给上‘ show-menu-by-longpress=‘1’’属性,就可以实现长按保存功能及长按识别图片中小程序二维码,特别方便 <image src="1.png" show-menu-by-longpress='1'></image> 1 二、点击按钮保存图片至相册 如果调取用户授权访问相册,在用户拒绝后,安卓会出现无法再继续保存的问题,这边给出苹果和安卓都适用的方法,代码如下: <button bindtap="savePoster"> 保存到相册 </button > 123 savePoster() { const that = this let fileName = new Date().valueOf(); let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg' //这边就是为了安卓做的兼容,因为安卓机有可能会将图片地址的后缀名读取为:unknow wx.downloadFile({ url: that.data.imgUrl, //需要保存的图片地址 filePath: filePath, success: function (res) { // 保存图片到系统相册 wx.saveImageToPhotosAlbum({ filePath: filePath, success(data) { let fileMgr = wx.getFileSystemManager() fileMgr.unlink({ filePath: filePath, success() { 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']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }) } } }) }, fail: function (res) {} }) }, 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 如果要调微信授权的保存相册,可以用以下代码: // 保存海报到相册 savePoster() { let that = this wx.getSetting({ success(res) { if (res.authSetting['scope.writePhotosAlbum']) { that.saveImg(); } else if (res.authSetting['scope.writePhotosAlbum'] === undefined) { wx.authorize({ scope: 'scope.writePhotosAlbum', success() { that.saveImg(); }, fail() { that.authConfirm() } }) } else { that.authConfirm() } } }) }, // 授权拒绝后,再次授权提示弹窗 authConfirm() { let that = this wx.showModal({ content: '检测到您没打开保存图片权限,是否去设置打开?', confirmText: "确认", cancelText: "取消", success: function (res) { if (res.confirm) { wx.openSetting({ success(res) { if (res.authSetting['scope.writePhotosAlbum']) { that.saveImg(); } else { wx.showToast({ title: '您没有授权,无法保存到相册', icon: 'none' }) } } }) } else { wx.showToast({ title: '您没有授权,无法保存到相册', icon: 'none' }) } } }); }, //保存图片 saveImg: function () { var that = this; var imgUrl = that.data.imgUrl; //需要保存的图片地址 console.log(imgUrl) wx.downloadFile({ url: imgUrl, success(res) { // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 console.log('downloadFileres', res); wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success(res) { console.log("保存图片:success"); wx.showToast({ title: '保存成功', }); }, fail: res => { console.log(res); wx.showToast({ title: '保存失败', }); } }) } }) }, 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 希望文章有帮助到您解决问题,瑞思拜~ 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/134469?site推荐阅读articlekali Linux的优点与缺点_kali everything优点...①超过300个渗透测试工具②永久免费③开源量无Git树④遵循FH线S⑤支持大设备⑥集成注入补丁的内核⑦安全的开发环境⑧包... 赞踩articleScratch少儿编程_scratch安卓平板...Scratch少儿编程1、介绍Scratch适合5、6岁以上的孩子,采用搭积木的方式实现编程。Scratch不是游戏,而... 赞踩article关于不同版本VS编译获得的静态库、动态库的兼容性_vs2015使用2013生成的动态库...MSDN文档中有所阐述 :C++Visual Studio 2015、2017和2019之间的二进制兼容性vs2013及... 赞踩articlePython+Django+SQLite 制作TO-DO list(四、视图逻辑部分views)_d...这个部分按照我个人的理解,就是用户通过浏览你的网页看到的内容。通过views中的一系列指令从数据库中获取所需的数据,并通... 赞踩article【unity3D】Transform组件(如何访问和获取Transform组件)_unity 获得t...unity 获得transform ... 赞踩article[Python] pytorch损失函数之MSELoss(均方误差损失)介绍和使用场景_mse_lo...pytorch损失函数之MSELoss(均方误差损失)介绍和使用场景_mse_loss pythonmse_loss p... 赞踩articleNLP-D22-cs224n&UNICORN&多层感知机&房价预测kaggle_kaggle波士顿房...–0519今天0430起床的,早上开始看cs224n,感觉老师好可爱!现在开始读论文啦!一、Unicorn—0558感觉... 赞踩articlereact-native 创建新的项目_react-native创建项目...react-native 创建新的项目一、安装node1、首先进入node官网,查看下载你所需要对应安装的node版本n... 赞踩article初试Vue之元素、属性赋值_vue 页面元素赋值...我们在vue中数据赋值时,会很自然而然的想到用“Mustache” 双大括号插值法来赋值在一个小案例中,比如给一个img... 赞踩article在项目中如何利用JS去修改CSS的属性值(二) --- :root+var()方法_js修改:roo...之前我写过一篇博客,是通过 JS+Sass变量修改CSS的属性值的方式来实现的该需求,但在后续的测试过程中我发现,这个方... 赞踩article让ChatGPT调用10万+开源AI模型!HuggingFace新功能爆火:大模型可随取随用多模态A...萧箫 发自 凹非寺量子位 | 公众号 QbitAI只需和ChatGPT聊聊天,它就能帮你调用10万+个HuggingFa... 赞踩articleOpenAI 今天刷屏的Sora视频模型,对未来影响几何?...美术风格是3D和现实的,重点是照明和纹理。虽然在此之前,Runway Gen 2、Pika等AI视频工具已经发布过类似的... 赞踩articleGPT-3.5 接口教程 | 实现计数窗口的大数据处理_android 如果和接入gpt3.5...计数窗口是一个时间或大小上固定的区间,在该区间内的数据将被分组和处理。一旦到达窗口的结尾,我们就可以对窗口中的数据进行聚... 赞踩article使用 three.js 中的 CSS3DRenderer 实现 3d 卡片的效果...前言最近要做一个 3D 卡片的效果,设计图如下:第一次尝试第一次尝试选择了我比较熟悉的 PixiJS,关于我如何用 Pi... 赞踩articlejava包名native包名_react-native android app名字 app包名、图标...1.设置名字 打开 android/app/src/main/res/values/strings.xml 如图,进行修... 赞踩article智能三子棋(人机大战)—— 你会是最终赢家吗?万字讲解让你实现与自己对弈...万字讲解带你实现智能三子棋,你与另一个自己谁会胜利?智能三子棋(人机大战)—— 你会是最终赢家吗?万字讲解让你实现与自己... 赞踩article数据库复习题选择题+判断题+填空题(考试续命必备_数据库建模与设计选择题...数据库复习题选择题+判断题+填空题(考试续命必备一些选择题1、从计算机数据管理的角度看,信息就是数据,数据就是信息。(B... 赞踩articlepython turtle画烟花_用Python写一个绚丽的烟花!...Python人工智能 - 一节课快速认识人工智能必备语言:python - 创客学院直播室www.makeru.com... 赞踩articleJava小区车位智能管理系统(毕设源码+mysql+lw)_小区车位检测管理系统毕业设计...首先,该系统可以实现车位的智能化管理,通过传感器等设备实时监控车位的使用情况,为车主提供准确的车位信息,避免车辆乱停乱放... 赞踩article【老生谈算法】matlab实现太阳黑子周期仿真源码——太阳黑子周期仿真_matlab太阳黑子...由图可以看出,太阳黑子活动大约有一定的周期性,大约是十几年。title(‘太阳黑子年平均出现次数’)太阳黑子的年平均出现... 赞踩相关标签kali linuxunity学习教程笔记pythonpytorch自然语言处理深度学习react nativevue属性和元素赋值vue中src赋值属性v-bind赋值cssjavascript前端人工智能chatgpt开源gpt-3开发语言大数据jsonViewUI
赞
踩
只需要image标签给上‘ show-menu-by-longpress=‘1’’属性,就可以实现长按保存功能及长按识别图片中小程序二维码,特别方便
<image src="1.png" show-menu-by-longpress='1'></image>
如果调取用户授权访问相册,在用户拒绝后,安卓会出现无法再继续保存的问题,这边给出苹果和安卓都适用的方法,代码如下:
<button bindtap="savePoster"> 保存到相册 </button >
savePoster() { const that = this let fileName = new Date().valueOf(); let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg' //这边就是为了安卓做的兼容,因为安卓机有可能会将图片地址的后缀名读取为:unknow wx.downloadFile({ url: that.data.imgUrl, //需要保存的图片地址 filePath: filePath, success: function (res) { // 保存图片到系统相册 wx.saveImageToPhotosAlbum({ filePath: filePath, success(data) { let fileMgr = wx.getFileSystemManager() fileMgr.unlink({ filePath: filePath, success() { 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']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }) } } }) }, fail: function (res) {} }) },
// 保存海报到相册 savePoster() { let that = this wx.getSetting({ success(res) { if (res.authSetting['scope.writePhotosAlbum']) { that.saveImg(); } else if (res.authSetting['scope.writePhotosAlbum'] === undefined) { wx.authorize({ scope: 'scope.writePhotosAlbum', success() { that.saveImg(); }, fail() { that.authConfirm() } }) } else { that.authConfirm() } } }) }, // 授权拒绝后,再次授权提示弹窗 authConfirm() { let that = this wx.showModal({ content: '检测到您没打开保存图片权限,是否去设置打开?', confirmText: "确认", cancelText: "取消", success: function (res) { if (res.confirm) { wx.openSetting({ success(res) { if (res.authSetting['scope.writePhotosAlbum']) { that.saveImg(); } else { wx.showToast({ title: '您没有授权,无法保存到相册', icon: 'none' }) } } }) } else { wx.showToast({ title: '您没有授权,无法保存到相册', icon: 'none' }) } } }); }, //保存图片 saveImg: function () { var that = this; var imgUrl = that.data.imgUrl; //需要保存的图片地址 console.log(imgUrl) wx.downloadFile({ url: imgUrl, success(res) { // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 console.log('downloadFileres', res); wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success(res) { console.log("保存图片:success"); wx.showToast({ title: '保存成功', }); }, fail: res => { console.log(res); wx.showToast({ title: '保存失败', }); } }) } }) },
希望文章有帮助到您解决问题,瑞思拜~