在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>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有