收藏
回答

微信小程序中用canvas给图片添加水印出现:部分安卓机添加完水印后图片变成黑色了?

这是我的代码片段:

that.w = width + 'px';
				that.h = height + 'px';
				that.imageNum = that.imageNumPro();
				that.waterMarkTime = that.getTimer();
				let ctx = uni.createCanvasContext('firstCanvas'); /** 创建画布 */
				//将图片src放到cancas内,宽高为图片大小
				ctx.drawImage(tempFilePaths, 0, 0, width, height);
				ctx.setFontSize(14);
				ctx.setFillStyle('red');
				ctx.fillText(that.waterMarkTime + ' ' + that.week, 10, height - 80);
				ctx.fillText(that.address, 10, height - 20);
				ctx.setFillStyle('blue');
				ctx.translate(100, 100);
				ctx.rotate(20 * Math.PI / 180);
				ctx.fillText(that.imageNum, width / 4, 20);
				ctx.draw(false, () => {
					setTimeout( () => {
						uni.canvasToTempFilePath({
							canvasId: 'firstCanvas',
							fileType: 'jpg',
							quality: 0.2,
							success: async (res1) => {
								console.log(res1);
								var tempFilePath = res1.tempFilePath;
								let imageInfo = await that.getFileInfo(res1.tempFilePath);
								
								that.uploadTask(imageUrl, tempFilePath);


							},
							fail:function(err){
								
							}
						});
					}, 500);
				});
回答关注问题邀请回答
收藏

1 个回答

  • Tao
    Tao
    2023-06-25

    怎么优化呢

    2023-06-25
    有用
    回复
登录 后发表内容