1、線上圖片地址(http、https):

源碼:
downLoad() {
? ? ? ? plus.nativeUI.showWaiting('loading...');
? ? ? ? var that = this;
? ? ? ? ? ? var dtask = plus.downloader.createDownload('imgUrl', {}, function (d, status) {
? ? ? ? ? ? ? // 下載完成
? ? ? ? ? ? ? if (status == 200) {
? ? ? ? ? ? ? ? plus.gallery.save(d.filename, function () {//保存到相冊(cè)方法
? ? ? ? ? ? ? ? ? plus.nativeUI.closeWaiting()
? ? ? ? ? ? ? ? ? plus.nativeUI.toast('<div>已保存到手機(jī)相冊(cè)</div>',{
? ? ? ? ? ? ? ? ? ? type:'richtext'
? ? ? ? ? ? });
? ? ? ? ? ? ? ? }, function () {
? ? ? ? ? ? ? ? ? plus.nativeUI.closeWaiting()
? ? ? ? ? ? ? ? ? plus.nativeUI.toast('<div>下載失敗,請(qǐng)重試</div>',{
? ? ? ? ? ? ? ? ? ? type:'richtext'
? ? ? ? ? ? });
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? plus.nativeUI.closeWaiting()
? ? ? ? ? ? ? ? plus.nativeUI.toast('<div>下載失敗,請(qǐng)重試</div>',{
? ? ? ? ? ? ? ? ? ? type:'richtext'
? ? ? ? ? ? });
? ? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? ? ? dtask.start();
? ? }
2、canvas合成base64圖片下載
轉(zhuǎn)載:http://www.itdecent.cn/p/c336fa712da9

源碼:
downLoad (base64,?success,?error)?{
? plus.nativeUI.showWaiting('loading...');
??var?bitmap?=?new?window.plus.nativeObj.Bitmap('image');? // 創(chuàng)建Bitmap對(duì)象
? var that = this;
? // 調(diào)用load/loadBase64Data方法加載圖片
??bitmap.loadBase64Data(base64,?function?(i)?{
that.bigmapToSave(bitmap,?success,?error)
??},?function?(err)?{
plus.nativeUI.closeWaiting()
????window.plus.nativeUI(err.message)
??})
},
// 調(diào)用保存bitmap的圖片到本機(jī)系統(tǒng)文件,為之后相冊(cè)保存提供路徑
bigmapToSave?(bitmap,?success,?error)?{
??var?name?=?this.randomString(10)
? var that = this;
??bitmap.save(`_doc/${name}.jpg`,?{?overwrite:?false?},?function?(event)?{
????console.log(event.target)
that.imageSaveByGallery(event.target,?success,?error)
??},?function?(err)?{
plus.nativeUI.closeWaiting()
????window.plus.nativeUI(err.message)
??})
},
// 圖片保存
imageSaveByGallery?(url,?success,?error)?{
??window.plus.gallery.save(url,?function?(event)?{
????const?tarbitmap?=?window.plus.nativeObj.Bitmap.getBitmapById('image')
????tarbitmap.clear()
plus.nativeUI.closeWaiting()
????plus.nativeUI.toast('<div>已保存到手機(jī)相冊(cè)</div>',{
? ? ? ? ? ? ? ? ? ? type:'richtext'
? ? ? ? });
??},?function?(err)?{
plus.nativeUI.closeWaiting()
????plus.nativeUI.toast('<div>下載失敗,請(qǐng)重試</div>',{
? ? ? ? ? ? ? ? ? ? type:'richtext'
? ? ? ? ? ? });
??})
},
randomString (e)?{
??var d?=?e?||?32
??var?t?=?'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
??var?a?=?t.length
??var?n?=?''
??for?(var?i?=?0;?i?<?d;?i++)?n?+=?t.charAt(Math.floor(Math.random()?*?a))
??return?n
},