본문 바로가기

html | javascript

html javascript - canvas imageData

const canvas = document.createElement('canvas')
canvas.width = 200
canvas.height = 200
document.body.appendChild(canvas)
const ctx = canvas.getContext('2d')
const imgData = ctx.createImageData(100, 100)
for (let i=0; i<imgData.data.length; i+=4) {
  imgData.data[i + 0] = 255
  imgData.data[i + 1] = 0
  imgData.data[i + 2] = 0
  imgData.data[i + 3] = 255
}
ctx.putImageData(imgData, 10, 10)