From a83e43af396752569eb10cadc11e8465e8bc71f3 Mon Sep 17 00:00:00 2001 From: ShenQiLun <97694732@qq.com> Date: Fri, 26 Jun 2026 09:48:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=94=A8canvas=E8=A3=81=E5=89=AA=E7=BC=A9?= =?UTF-8?q?=E6=94=BE1080=C3=971080=E6=9B=BF=E4=BB=A3plus.zip(=E4=B8=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9nvue)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/camera_capture.nvue | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/pages/upload/camera_capture.nvue b/pages/upload/camera_capture.nvue index 12dc27f..87cf61b 100644 --- a/pages/upload/camera_capture.nvue +++ b/pages/upload/camera_capture.nvue @@ -66,6 +66,9 @@ + + + @@ -141,27 +144,28 @@ var w = info.width var h = info.height var size = Math.min(w, h) - var clipX = Math.floor((w - size) / 2) - var clipY = Math.floor((h - size) / 2) - plus.zip.compressImage({ - src: srcPath, - dst: '_doc/sq_' + Date.now() + '.jpg', - width: '1080', - height: '1080', - quality: 95, - overwrite: true, - clip: { - x: clipX, - y: clipY, - width: size, - height: size - } - }, - function(res) { - that.capturedList.push(res.target) - }, - function() { - that.capturedList.push(srcPath) + var sx = Math.floor((w - size) / 2) + var sy = Math.floor((h - size) / 2) + // 用canvas裁剪 + 缩放 + var ctx = uni.createCanvasContext('resizeCanvas', that) + ctx.drawImage(srcPath, sx, sy, size, size, 0, 0, 1080, 1080) + ctx.draw(false, function() { + setTimeout(function() { + uni.canvasToTempFilePath({ + canvasId: 'resizeCanvas', + x: 0, y: 0, + width: 1080, height: 1080, + destWidth: 1080, destHeight: 1080, + fileType: 'jpg', + quality: 1, + success: function(res) { + that.capturedList.push(res.tempFilePath) + }, + fail: function() { + that.capturedList.push(srcPath) + } + }, that) + }, 300) }) }, fail: function() {