微信小程序保存圖片的方法


1、xhtml代碼

長按保存:

<view class="img"  catchlongpress='baocun'></view>

 

2、Js代碼

baocun: function (e) { wx.showModal({ title: '提示', content: '確定要保存這張圖片嗎?', success: function (res) { if (res.confirm) { console.log('用戶點擊確定') wx.getImageInfo({ src: 'xxxxxxx', success: function (res) { console.log(res); var path = res.path; wx.saveImageToPhotosAlbum({ filePath: path, success: function (res) { console.log('圖片已保存'); }, fail: function (res) { console.log('保存失敗'); } }) } }); } else if (res.cancel) { console.log('用戶點擊取消') } } }) },

 

詳情可參考小程序文檔


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM