H5画布不显示图片的问题解决

在onReady 执行

<template>
	<view class="">
		<canvas style="" canvas-id="myCanvas" id="myCanvas"></canvas>
		<!-- <view class="container">
			<img :src="tempFilePath" />
		</view> -->
	</view>

</template>

<script>
	var that
	export default {
		data() {
			return {
				tempFilePath: ''
			}
		},
		onReady(option) {
			that = this;
			const ctx = uni.createCanvasContext('myCanvas')
			// uni.chooseImage({
			//   success: function(res){
			    ctx.drawImage('../../static/sharePoster_bg.png', 0, 0, 150, 100)
			    ctx.draw()
			  // }
			// })
		},
		methods: {
		}
	}
</script>

<style lang="scss" scoped>
</style>

 

   

<template>
	<view class="">
		<canvas style="" canvas-id="myCanvas" id="myCanvas"></canvas>
		<view class="container">
			<image :src="tempFilePath" mode="widthFix"></image>
		</view>
	</view>

</template>

<script>
	var that
	export default {
		data() {
			return {
				tempFilePath: ''
			}
		},
		onReady(option) {
			that = this;
			const ctx = uni.createCanvasContext('myCanvas')

			ctx.drawImage('../../static/sharePoster_bg.png', 0, 0, 200, 380)
			ctx.fillStyle="#005B8C";
			ctx.font = "bold 60px Arial";
			// ctx.setFontStyle('color','#005B8C')
			ctx.fillText('A+', 15, 126)
			ctx.draw(true, () => {
				uni.canvasToTempFilePath({
					x: 0,
					y: 0,
					width: 200,
					height: 380,
					destWidth: getApp().windowWidth,
					destHeight: getApp().windowWidth/200*380,
					canvasId: 'myCanvas',
					fileType: "jpg",
					quality: 1,
					success(res) {
						console.log('绘制成功-------', res)
						uni.hideLoading();
						that.tempFilePath = res.tempFilePath;
					},
					fail(err) {
						console.log('绘制失败', err)
					}
				});
			});
		},
		methods: {}
	}
</script>

<style lang="scss" scoped>
	canvas {
			background-color: #fff;
			border: 1px solid #d0d0d0;
			width: 100vw;
			height: 100vh;
			position: absolute;
			left: 100%;
		}
	 
		.container {
			width: 100vw;
			align-items: center;
			overflow: auto;
			background: #fefefe;
		}
	 
		.container image {
			width: 100%;
			position: absolute;
			top: 0;
		}
</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a_靖

对你有帮助吗?打赏鼓励一下?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值