预览图片
previewImg(src) {
let that = this
let imgsArray = [];
imgsArray[0] = src
uni.previewImage({
current: 0,
urls: imgsArray,
longPressActions: {
itemList: ['保存图片'],
success: function(data) {
that.saveBaseImgFile(src)
},
fail: function(err) {
console.log(err.errMsg);
}
}
});
},
saveBaseImgFile处理base64图片并保存
saveBaseImgFile(src) {
let base64 = src;
const bitmap = new plus.nativeObj.Bitmap("base64");
//loadBase64Data将base64字符串转换为bitmap文件对象
bitmap.loadBase64Data(base64, function() {
const url = "_zhongzi/" + new Date().getTime() + ".png";
console.log('saveHeadImgFile', url)
//这里调用API存储图片至存储系统,才可以保存下来
bitmap.save(url, {
overwrite: true, // 是否覆盖
quality: 'quality' // 图片清晰度
}, (i) => {
//调用uniapp保存图片api
uni.saveImageToPhotosAlbum({
filePath: i.target,
success: function() {
uni.showToast({
title: '图片保存成功',
icon: 'none'
})
bitmap.clear()
},
fail: function(err) {
uni.showToast({
title: '图片保存失败',
icon: 'none'
})
console.log(err.errMsg);
}
});
}, (e) => {
uni.showToast({
title: '图片保存失败',
icon: 'none'
})
bitmap.clear()
});
}, (e) => {
uni.showToast({
title: '图片保存失败',
icon: 'none'
})
bitmap.clear()
});
},