uniapp 动态保存图片

html

<image :src="qrcodeImg" @longtap="shareImg"></image>

js

	shareImg() {
				let _this = this
				let ws = this.$mp.page.$getAppWebview();
				let bitmap = new plus.nativeObj.Bitmap();
				this.$nextTick(function(){
					setTimeout(()=>{
						ws.draw(bitmap,(e)=>{
							console.log('bitmap绘制图片成功');
							console.log("e: " + JSON.stringify(e));
							bitmap.save("my.jpg", {
								overwrite: true,
								quality: 100
							}, (i)=>{
								plus.gallery.save(i.target,(e)=>{
									uni.showToast({
										title:'保存成功'
									})
									bitmap.clear(); //销毁
								},(e)=>{
									bitmap.clear(); //销毁
								});
							},(e)=>{
								uni.showToast({
										title:'保存失败'
									})
								console.log('保存图片失败:' + JSON.stringify(e));
							});
						},(e)=>{
							uni.showToast({
										title:'绘制图片失败'
									})
							console.log('bitmap绘制图片失败:'+JSON.stringify(e));
						});
					},200)
				})
			}

猜你喜欢

转载自blog.csdn.net/weixin_55552785/article/details/119537310