This commit is contained in:
tamaina 2023-04-12 14:16:28 +00:00
parent bb0036ae22
commit b01c22c647
1 changed files with 13 additions and 13 deletions

View File

@ -31,23 +31,10 @@ let loaded = $ref(false);
let width = $ref(props.width);
let height = $ref(props.height);
function draw() {
if (props.hash == null) return;
const pixels = decode(props.hash, props.width, props.height);
const ctx = canvas.getContext('2d');
const imageData = ctx!.createImageData(props.width, props.height);
imageData.data.set(pixels);
ctx!.putImageData(imageData, 0, 0);
}
function onLoad() {
loaded = true;
}
watch(() => props.hash, () => {
draw();
});
watch([() => props.width, () => props.height], () => {
const ratio = props.width / props.height;
if (ratio > 1) {
@ -61,6 +48,19 @@ watch([() => props.width, () => props.height], () => {
immediate: true,
});
function draw() {
if (props.hash == null) return;
const pixels = decode(props.hash, width, height);
const ctx = canvas.getContext('2d');
const imageData = ctx!.createImageData(props.width, props.height);
imageData.data.set(pixels);
ctx!.putImageData(imageData, 0, 0);
}
watch(() => props.hash, () => {
draw();
});
onMounted(() => {
draw();
});