Last active
December 1, 2018 08:31
-
-
Save rssilva/ade348dd4014f3d5962ff4d9a179d26f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// doing a query to get the element on html file | |
const canvas = document.querySelector('#canvas') | |
// getting the canvas context | |
const context = canvas.getContext('2d') | |
// Let's create an Image instance | |
const baseImage = new Image() | |
// 'low.jpg' is the image path on your file system | |
baseImage.src = 'low.jpg' | |
// callback that will be called when the image is loaded | |
baseImage.onload = () => { | |
// getting the width and height from canvas | |
const { width, height } = context.canvas | |
// drawing the image on the canvas | |
context.drawImage(baseImage, 0, 0, width, height) | |
// this method will return the data from the drawed image | |
const imageData = context.getImageData(0, 0, width, height) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment