mirror of
https://github.com/silenty4ng/k5web
synced 2025-01-08 21:04:19 +00:00
update
This commit is contained in:
parent
9b1517dfcd
commit
8fa70ed4b8
1 changed files with 27 additions and 4 deletions
|
@ -16,6 +16,7 @@
|
||||||
<br>
|
<br>
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-button @click="selectFile">{{ $t('tool.selectImage') }}</a-button>
|
<a-button @click="selectFile">{{ $t('tool.selectImage') }}</a-button>
|
||||||
|
<a-button :disabled="state.matrix.length < 64" @click="saveIt">保存</a-button>
|
||||||
<a-button type="primary" :disabled="state.matrix.length < 64" @click="flashIt">{{ $t('tool.write') }}</a-button>
|
<a-button type="primary" :disabled="state.matrix.length < 64" @click="flashIt">{{ $t('tool.write') }}</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
</a-card>
|
</a-card>
|
||||||
|
@ -108,10 +109,6 @@ const selectFile = () => {
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
canvas.width = 128;
|
canvas.width = 128;
|
||||||
canvas.height = 64;
|
canvas.height = 64;
|
||||||
const canvas2 = canvas.cloneNode();
|
|
||||||
const canvasDiv = document.getElementById('canvasDiv');
|
|
||||||
canvasDiv.innerHTML = "";
|
|
||||||
canvasDiv?.append(canvas, canvas2);
|
|
||||||
|
|
||||||
const img = new Image()
|
const img = new Image()
|
||||||
img.src = file;
|
img.src = file;
|
||||||
|
@ -142,6 +139,32 @@ const selectFile = () => {
|
||||||
input.click();
|
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 flashIt = async () => {
|
||||||
const outputArray = new Uint8Array(1024);
|
const outputArray = new Uint8Array(1024);
|
||||||
// getPixel(i) outputs the pixel value for any x y coordinate. 0 = black, 1 = white.
|
// getPixel(i) outputs the pixel value for any x y coordinate. 0 = black, 1 = white.
|
||||||
|
|
Loading…
Reference in a new issue