diff --git a/src/views/list/image/index.vue b/src/views/list/image/index.vue index 3b46d2b..726e481 100644 --- a/src/views/list/image/index.vue +++ b/src/views/list/image/index.vue @@ -16,6 +16,7 @@
{{ $t('tool.selectImage') }} + 保存 {{ $t('tool.write') }} @@ -108,10 +109,6 @@ const selectFile = () => { const canvas = document.createElement("canvas"); canvas.width = 128; canvas.height = 64; - const canvas2 = canvas.cloneNode(); - const canvasDiv = document.getElementById('canvasDiv'); - canvasDiv.innerHTML = ""; - canvasDiv?.append(canvas, canvas2); const img = new Image() img.src = file; @@ -142,6 +139,32 @@ const selectFile = () => { input.click(); } +const saveIt = async () => { + const matrix = state.matrix + const canvas = document.createElement("canvas"); + canvas.width = 128; + canvas.height = 64; + const ctx = canvas.getContext('2d'); + if(ctx){ + ctx.fillStyle = "#fff"; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.fillStyle = "#000"; + } + for (let y = 0; y < 64; y++) { + for (let x = 0; x < 128; x++) { + if(matrix[y][x] == '#000'){ + ctx?.beginPath(); + ctx?.rect(x, y, 1, 1); + ctx?.fill(); + } + } + } + const el = document.createElement('a'); + el.href = canvas.toDataURL("image/jpeg", 1.0); + el.download = 'image.jpg'; + el.click() +} + const flashIt = async () => { const outputArray = new Uint8Array(1024); // getPixel(i) outputs the pixel value for any x y coordinate. 0 = black, 1 = white.