← Back to context

Comment by creata

2 days ago

    const input = document.createElement("input");
    document.body.append(input);
    input.type = "file";
    input.accept = "image/*";
    input.onchange = e => {
        if (input.files && input.files[0]) {
            const canvas = document.getElementById("draw-canvas");
            const ctx = canvas.getContext("2d");
            createImageBitmap(input.files[0]).then(img => ctx.drawImage(img, 0, 0));
        }
    };