uni.canvasToTempFilePath 生成的临时路径在iOS端无法显示,或者显示空白

  重点是一定要压缩图片!!!!!
<canvas style="position: absolute;left: -5000px;" :style="{'width':w,'height': h}" canvas-id="firstCanvas"
			ref="mycanvas"></canvas>
			//拍照
			photograph() {
				let _this = this
				uni.chooseImage({
					count: 1,
					sourceType: ['camera'],
					sizeType: ['compressed'], //选择图片的大小
					success(res) {
						let images = res.tempFilePaths;
						//压缩图片大小。必须的!!!!!!!!
						uni.compressImage({
							src: images[0],
							quality: 30,
							width: '40%',
							height: '40%',
							success(res2) {
								uni.getImageInfo({
									src: res2.tempFilePath,
									success: (r) => {
										_this.canvasWather(r, _this.getNowTime_1())

									},
									fail: () => {
										console.log('失败了吗');
									}
								})
							}
						})


					}
				})
			},
		添加水印    _this.getNowTime_1()  这个是我自定义的时间函数,看个人需求
      canvasWather(res, time) {
				const user = uni.getStorageSync('userInfo')
				let that = this;
				let ctx = uni.createCanvasContext('firstCanvas', that);
				that.w = res.width / 2 + 'px';
				that.h = res.height / 2 + 'px';
				uni.showLoading({
					title: '正在上传',
				})
				setTimeout(() => {
					//初始化画布
					ctx.fillRect(0, 0, res.width / 2, res.height / 2);
					// //将图片src放到cancas内,宽高为图片大小
					ctx.drawImage(res.path, 0, 0, res.width / 2, res.height / 2);
					ctx.beginPath()
					ctx.setFontSize(10)
					ctx.setFillStyle('green');
					let firstY = res.height / 2 - 60;
					
					ctx.fillText(`${time}`, 10, firstY + 20)
					ctx.draw(false, () => {
					//
						uni.canvasToTempFilePath({
							canvasId: 'firstCanvas',
							success: (res) => {
								that.saveFile(res);
								uni.hideLoading();
							},
							fail: (err) => {
								console.log("什么问题");
							}
						})
					})

				}, 500)
			},
 保存
    saveFile(res) {
				let _this = this
				uni.saveFile({
					tempFilePath: res.tempFilePath,
					success(r) {
						_this.tempFilePath = r.savedFilePath
						_this.photoList.push(
							r.savedFilePath
						)
					}
				})

			},
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值