From 9ed5a3e708274beea83487c10e77c29bc843f1e7 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Mon, 2 May 2022 18:48:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20WritingBoard=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/WritingBoard.vue | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/WritingBoard.vue b/src/components/WritingBoard.vue index eb7051d1..4d7b8df8 100644 --- a/src/components/WritingBoard.vue +++ b/src/components/WritingBoard.vue @@ -291,6 +291,21 @@ export default defineComponent({ ctx.clearRect(0, 0, canvasRef.value.width, canvasRef.value.height) } + // 获取 DataURL + const getImageDataURL = () => { + return canvasRef.value?.toDataURL() + } + + // 设置 DataURL(绘制图片到 canvas) + const setImageDataURL = (imageDataURL: string) => { + const img = new Image() + img.src = imageDataURL + img.onload = () => { + if (!ctx) return + ctx.drawImage(img, 0, 0) + } + } + return { mouse, mouseInCanvas, @@ -305,6 +320,8 @@ export default defineComponent({ handleMousemove, handleMouseup, clearCanvas, + getImageDataURL, + setImageDataURL, } }, })