<template>
<view class="content">
<view class="item" v-for="(item, index) in 20" :key="index">
{{item}}
</view>
<view class="" @click="saveClick">
保存
</view>
</view>
</template>
<script>
export default {
created() {},
methods: {
saveClick() {
var pages = getCurrentPages(); //获取当前页面信息
var page = pages[pages.length - 1];
var bitmap = null;
var currentWebview = page.$getAppWebview();
bitmap = new plus.nativeObj.Bitmap('amway_img');
// 将webview内容绘制到Bitmap对象中
currentWebview.draw(bitmap, function() {
// console.log('截屏绘制图片成功');
//这里我将文件名用四位随机数拼接了,不然会出现当前图片替换上一张图片只能保存一张图片的问题
let rand = Math.floor(Math.random() * 10000)
let saveUrl = '_doc/' + rand + 'a.jpg'
bitmap.save(saveUrl, {}, function(i) {
// console.log('保存图片成功:' + JSON.stringify(i));
uni.saveImageToPhotosAlbum({
filePath: i.target,
success: function() {
// bitmap.clear(); //销毁Bitmap图片
uni.showToast({
title: '保存图片成功',
mask: false,
duration: 1500
});
}
});
}, function(e) {
console.log('保存失败' + JSON.stringify(e));
});
}, function(e) {
console.log('截屏绘制图片失败' + JSON.stringify(e));
});
}
}
}
</script>
<style>
.item {
margin: 40px;
}
</style>
uni-app app端截取整个页面成图片并保存
最新推荐文章于 2024-04-27 22:28:07 发布