Created
October 10, 2017 02:17
-
-
Save rssilva/4e62cc809121e8ef012513fe13aec1bc 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
// fazendo uma query do elemento presente no arquivo html | |
const canvas = document.querySelector('#canvas') | |
// obtendo o contexto de canvas | |
const context = canvas.getContext('2d') | |
// Vamos criar uma instância de Imagem | |
const baseImage = new Image() | |
// 'lena.jpg' é o caminho da imagem no nosso sistema de arquivos | |
baseImage.src = 'lena.jpg' | |
// callback que será chamado quando a imagem for carregada | |
baseImage.onload = () => { | |
// atribuindo a largura e altura da imagem | |
const { width, height } = context.canvas | |
// desenhando a imagem no canvas | |
context.drawImage(baseImage, 0, 0, width, height) | |
// o método getImageData retorna a informação da imagem | |
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