Skip to content

Instantly share code, notes, and snippets.

@av01d
Created July 23, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save av01d/5c56122bfae58ba52fb19ec154585767 to your computer and use it in GitHub Desktop.
Save av01d/5c56122bfae58ba52fb19ec154585767 to your computer and use it in GitHub Desktop.
File to Bitmap (on canvas)
/* HTML:
<input type="file" id="filepicker">
<canvas id="outCanvas"></canvas>
*/
filepicker.addEventListener("change", () => {
createImageBitmap(filepicker.files[0])
.then(response => {
outCanvas.width = response.width;
outCanvas.height = response.height;
const ctx = outCanvas.getContext("2d");
ctx.drawImage(response, 0, 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment