找了很多例子 都不起作用,然后搜索到一个大佬的 代码然后试了试
teamShare 是服务端返回的图片
<view class="sign-box" v-if="teamShare">
<image :src="'data:image/jpg;base64,'+ teamShare" mode="" @tap="save" @longtap="toSave" class="teamShare"></image>
</view>
app 端的图片是服务端返回bese64的图片
toSave() {
uni.showModal({
title: '图片保存',
content: '确定要保存图片吗',
success: e => {
if (e['confirm']) {
// this.save();
let url = 'data:image/png;base64,'+this.teamShare
// this.savePhoto(url)
// #ifdef APP-PLUS
this.saveBase64Img(url)
// #endif
}
}
});
},
//保存图片
saveBase64Img(base64) {
let _this = this
const bitmap = new plus.nativeObj.Bitmap('test');
bitmap.loadBase64Data(
base64,
function() {
const url = '_doc/' + new Date() + '.png'; // url建议用时间戳命名方式
console.log('url:', url);
bitmap.save(
url,
{
overwrite: true // 是否覆盖
// quality: 'quality' // 图片清晰度
},
i => {
uni.saveImageToPhotosAlbum({
filePath: url,
success: function() {
console.log('保存成功');
uni.showToast({
title:'保存成功,请到手机相册'
})
_this.teamShare = null
bitmap.clear();
}
});
},
e => {
console.log('保存失败', e);
bitmap.clear();
}
);
},
e => {
console.log('保存失败', e);
bitmap.clear();
}
);
},