box11 为保存内容的id
saveImg() {
this.$toast.loading({
message: "保存中...",
forbidClick: true,
});
this.createPoster();
},
createPoster() {
const poster = document.getElementById("box11");
html2canvas(poster, {
dpi: window.devicePixelRatio * 2,
backgroundColor: "#fff",
useCORS: true,
scale: 2,
async: true,
}).then((canvas) => {
this.dataImg = canvas.toDataURL("image/png");
console.log(this.dataImg);
this.toImage();
});
},
toImage() {
let filename = "下载二维码" + ".png";
console.log(window.plus);
if (!window.plus) {
this.$toast("请长按图片保存到本地");
return;
}
console.log("保存");
let bitmap = new plus.nativeObj.Bitmap();
bitmap.loadBase64Data(this.dataImg);
bitmap.save(
"_doc/" + filename,
{
check: true, // 设置为检测白屏
overwrite: true,
quality: 100,
},
function(i) {
//保存到系统相册
plus.gallery.save(
i.target,
function(d) {
//销毁Bitmap图片
bitmap.clear();
plus.nativeUI.alert("保存图片到相册成功");
},
function(e) {
//销毁Bitmap图片
bitmap.clear();
plus.nativeUI.alert("保存到系统相册失败,请尝试重新保存");
}
);
},
function() {
plus.nativeUI.alert("保存失败,请尝试重新保存");
}
);
},