uniapp canvas 图片加上文字合成一张新图并保存到手机相册
背景图上是奖章徽章,中间加上自定义文本,我这个图是因为背景图上原来就有字,随便找的,所以跟我写的文字层叠了
具体实现代码
<template>
<view class="box">
<view class="box-title">
<view class="box-title_left">
{{'金奖'}}
</view>
人员:
<view class="box-title_right">
{{5}}人
</view>
</view>
<view class="box_center">
<view class="indeximg">
<canvas style="width: 96px;height: 96px; " canvas-id="firstCanvas"></canvas>
</view>
<view class="footer_btn">
<view class="">
</view>
<view class="download" @click="canimg">
保存到相册
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
name: "老薛真帅",
jin: "#F8E656"
};
},
onLoad() {
this.img()
uni.getSetting({
success(res) {
console.log(res.authSetting)
}
})
},
methods: {
img() {
let that = this
uni.getImageInfo({
src: "",//背景图路径,我用的网络图片,本地的没试过
success(res) {
console.log(res.path)
var ctx = uni.createCanvasContext("firstCanvas") // 使用画布创建上下文 图片
ctx.drawImage(res.path, 0, 0, 96,
96) // 设置图片坐标及大小,括号里面的分别是(图片路径,x坐标,y坐标,width,height)
ctx.setFontSize(12) //设置字体大小,默认10
ctx.setFillStyle(that.jin) //文字颜色:默认黑色
ctx.setTextAlign('center')//文本水平居中
ctx.fillText(that.name, 48, 54); //文字内容、x坐标,y坐标
ctx.save(); //保存
ctx.draw() //绘制
}
})
},
// canvas生成图片
canimg() {
let that = this
uni.canvasToTempFilePath({
destWidth: 400,
destHeight: 400,
canvasId: 'firstCanvas',
success: function(res) {
// 在H5平台下,tempFilePath 为 base64
console.log(res.tempFilePath, "//")
// 保存本地
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
console.log("成功")
uni.showToast({
icon: 'none',
position: 'bottom',
title: "图片已下载至【图库】,请打开【图库】查看", // res.tempFilePath
});
},
fail: function(err) {
console.log("失败", err)
}
})
}
})
},
}
}
</script>
<style lang="scss">
page {
background-color: #f4f5f9;
}
.box {
.box-title {
width: 100%;
color: #293444;
font-size: 36rpx;
display: flex;
align-items: center;
padding: 20rpx 20rpx;
.box-title_right {
color: #5572fe;
margin-left: 20rpx;
}
}
.box_center {
width: 100%;
height: 1310rpx;
background-color: #Fff;
border-radius: 32rpx 32rpx 0 0;
padding: 20rpx 20rpx;
margin-top: 48rpx;
.footer_btn{
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
height: 200rpx;
position: fixed;
left: 0;
bottom: 0;
padding: 20rpx 20rpx;
.download{
width: 280rpx;
height: 96rpx;
border-radius: 48rpx;
background-color: #4766FF;
text-align: center;
line-height: 96rpx;
color: #fff;
font-size: 32rpx;
}
}
}
}
</style>
表白失败那一刻,应该怎么做?
我喜欢她,她也喜欢我的女生,我们一起已经半年了。
是我表白的。
因为喜欢,所以不想错过。
如果你能看到这条更新,我想告诉你,喜欢就去争取吧!!!!
前些时间看到一条表白成功应该怎么做的问答,我喜欢了一个女生,想表白,各种不知所措。
就在半个小时前 我鼓起勇气 做了一个决定
我确定我喜欢她
我表白了
我在约她喝喜茶的地方表白了
这一次表白 我想了很多
在她不知道的时候 自己内心世界表白过很多遍
内心戏爆棚
我幻想过很多可能
我以为我这次能赢
我以为她有feel得到
我以为她明白我
我以为我一直努力为她变得更好她会知道
就好像一句话说 怎么知道你喜欢上一个人
“要是我更加优秀就好了”
我真的想更加更加优秀 变得更好
我说:“诶,你知道我为什么这么爽快答应和你一起搭档主持吗?其实我喜欢和你一起的感觉。第一次和你搭档的时候,我已经喜欢你了。”
应该就好像她所说的那样吧
“朋友都是这样没的”
“可能我只是纯粹当你是朋友”
表白当然是失败告终
她还放不下他
她问我“你觉得你的成功率多高?”
我“难道成功率不高,或者害怕失败,就不去做吗?”
我清楚自己我喜欢你 我骗不了自己的感情
可能会失去做朋友的机会
可是难道等到儿子都会打酱油再说出来吗
可能很幼稚 可是喜欢真的要说出来
如果没有考虑过以后的事 我是不会想和你在一起的
我的计划都是你
可是
我还是赢不了他
总结
是烟不好抽手机不好玩还是酒不好喝??
好好的学什么人表白??
大家保重(抱团)