ปรับ ขนาดรูป
This commit is contained in:
parent
e0112b45ed
commit
798e1e18e0
1 changed files with 61 additions and 31 deletions
|
|
@ -72,7 +72,7 @@
|
||||||
<q-img
|
<q-img
|
||||||
src="@/assets/map1.png"
|
src="@/assets/map1.png"
|
||||||
:style="
|
:style="
|
||||||
$q.screen.gt.xs ? 'height: 300px;' : 'height: 168px;'
|
$q.screen.gt.xs ? 'height: 350px;' : 'height: 168px;'
|
||||||
"
|
"
|
||||||
></q-img>
|
></q-img>
|
||||||
<div class="q-pa-md text-weight-medium text-grey-8">
|
<div class="q-pa-md text-weight-medium text-grey-8">
|
||||||
|
|
@ -98,45 +98,38 @@
|
||||||
color="blue-grey-3"
|
color="blue-grey-3"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="text-center q-pt-md text-grey-7">
|
|
||||||
ไม่มีรูปภาพ
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div v-if="hasPhoto">
|
<div v-if="hasPhoto">
|
||||||
<video
|
<video
|
||||||
ref="video"
|
ref="video"
|
||||||
autoplay
|
autoplay
|
||||||
:style="{
|
:style="
|
||||||
width: videoWidth + 'px',
|
$q.screen.gt.xs
|
||||||
height: videoHeight + 'px',
|
? 'width: 375px; height: 350px;'
|
||||||
}"
|
: 'width: 245px; height: 220px;'
|
||||||
|
"
|
||||||
></video>
|
></video>
|
||||||
<canvas
|
<canvas
|
||||||
ref="canvas"
|
ref="canvas"
|
||||||
:width="videoWidth"
|
:style="
|
||||||
:height="videoHeight"
|
$q.screen.gt.xs
|
||||||
|
? 'width: 375px; height: 350px;'
|
||||||
|
: 'width: 252px; height: 190px;'
|
||||||
|
"
|
||||||
></canvas>
|
></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="q-mt-sm">
|
<div v-else>
|
||||||
<q-img
|
<q-img
|
||||||
:src="img"
|
:src="img"
|
||||||
:style="{
|
:style="
|
||||||
width: videoWidth + 'px',
|
$q.screen.gt.xs
|
||||||
height: videoHeight + 'px',
|
? 'width: 375px; height: 350px; border-radius: 5px;'
|
||||||
}"
|
: 'width: 245px; height: 218px; border-radius: 5px;'
|
||||||
class="q-mt-lg"
|
"
|
||||||
></q-img>
|
></q-img>
|
||||||
<canvas
|
<canvas ref="canvas"></canvas>
|
||||||
ref="canvas"
|
|
||||||
:width="canvasWidth"
|
|
||||||
:height="canvasHeight"
|
|
||||||
:style="{
|
|
||||||
width: videoWidth + 'px',
|
|
||||||
height: videoHeight + 'px',
|
|
||||||
}"
|
|
||||||
></canvas>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="absolute-bottom-right q-ma-md">
|
<div class="absolute-bottom-right q-ma-md">
|
||||||
|
|
@ -306,11 +299,6 @@ const canvas = ref<HTMLCanvasElement | null>(null);
|
||||||
const hasPhoto = ref<boolean>(true);
|
const hasPhoto = ref<boolean>(true);
|
||||||
const img = ref<any>();
|
const img = ref<any>();
|
||||||
|
|
||||||
const videoWidth = ref<number>(335);
|
|
||||||
const videoHeight = ref<number>(350);
|
|
||||||
const canvasWidth = ref<number>(335);
|
|
||||||
const canvasHeight = ref<number>(350);
|
|
||||||
|
|
||||||
function capturePhoto() {
|
function capturePhoto() {
|
||||||
const videoElement = video.value;
|
const videoElement = video.value;
|
||||||
const canvasElement = canvas.value;
|
const canvasElement = canvas.value;
|
||||||
|
|
@ -323,7 +311,49 @@ function capturePhoto() {
|
||||||
console.error("Canvas context not available");
|
console.error("Canvas context not available");
|
||||||
return;
|
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");
|
const dataURL = canvasElement.toDataURL(".image/.png");
|
||||||
img.value = dataURL;
|
img.value = dataURL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue