uniapp截屏并保存到相册
let pages = getCurrentPages();
let page = pages[pages.length - 1];
let webView = page.$getAppWebview();
let bitmap = new plus.nativeObj.Bitmap('drawScreen');
webView.draw(bitmap, () => {
//保存到本地
bitmap.save('_doc/'+ datefmt(new Date(), 'YYYYMMDDHHmmss') + ".png", {
overwrite: true
}, res => {
const locationUrl = res.target; // 图片地址
console.log('本地路径:'+locationUrl)
//保存到相册
uni.saveImageToPhotosAlbum({
filePath:locationUrl,
success: function () {
console.log('save success');
}
});
bitmap.clear(); // 清除Bitmap对象
//分享给微信
uni.share({
provider: "weixin",
scene: "WXSceneSession",
type: 0,
href: this.shareUrl+"?source=app&shareId="+this.user.id,
title: this.shareTitle,
summary: this.shareContent,
imageUrl: locationUrl,
success: function (res) {
console.log("success:" + JSON.stringify(res));
},
fail: function (err) {
console.log("fail:" + JSON.stringify(err));
}
});
}, error => {
console.log(JSON.stringify(error)); // 保存失败信息
bitmap.clear(); // 清除Bitmap对象
});
}, error => {
console.log(JSON.stringify(error)); // 绘制失败
}, {
check: true, // 设置为检测白屏
});
注意:android云端打包后可能出现-100错误,检查manifest.json权限配置