From 798e1e18e0010e33d003d3ac7e5af9c36ee3711a Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 1 Nov 2023 18:05:12 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20?= =?UTF-8?q?=E0=B8=82=E0=B8=99=E0=B8=B2=E0=B8=94=E0=B8=A3=E0=B8=B9=E0=B8=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/04_checkin/views/Checkin.vue | 92 ++++++++++++++++-------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/src/modules/04_checkin/views/Checkin.vue b/src/modules/04_checkin/views/Checkin.vue index 12138b7..9e92aba 100644 --- a/src/modules/04_checkin/views/Checkin.vue +++ b/src/modules/04_checkin/views/Checkin.vue @@ -72,7 +72,7 @@
@@ -98,45 +98,38 @@ color="blue-grey-3" />
-
-
+
- +
@@ -306,11 +299,6 @@ const canvas = ref(null); const hasPhoto = ref(true); const img = ref(); -const videoWidth = ref(335); -const videoHeight = ref(350); -const canvasWidth = ref(335); -const canvasHeight = ref(350); - function capturePhoto() { const videoElement = video.value; const canvasElement = canvas.value; @@ -323,7 +311,49 @@ function capturePhoto() { console.error("Canvas context not available"); return; } - context.drawImage(videoElement, 0, 0, 335, 270); + const desiredWidth = 189; + const desiredHeight = 190; + const zoomFactor = 10; + + const videoAspectRatio = videoElement.videoWidth / videoElement.videoHeight; + const canvasAspectRatio = desiredWidth / desiredHeight; + + let drawWidth, drawHeight; + + if (videoAspectRatio > canvasAspectRatio) { + drawWidth = desiredWidth * zoomFactor; + drawHeight = (desiredWidth * zoomFactor) / videoAspectRatio; + } else { + drawWidth = desiredHeight * zoomFactor * videoAspectRatio; + drawHeight = desiredHeight * zoomFactor; + } + + canvasElement.width = drawWidth; + canvasElement.height = drawHeight; + if (context) { + context.imageSmoothingEnabled = true; + context.imageSmoothingQuality = "high"; + } + + // context.drawImage( + // videoElement, + // 0, + // 0, + // canvasElement.width, + // canvasElement.height + // ); + context.drawImage( + videoElement, + 0, + 0, + videoElement.videoWidth, + videoElement.videoHeight, + 0, + 0, + drawWidth, + drawHeight + ); + //ไฟล์รูป const dataURL = canvasElement.toDataURL(".image/.png"); img.value = dataURL;