Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
Depixelize an image

I am looking for a way to depixelize an image that I pixelized with this code. I want to know if I can change the samplesize variable value with an event listener or something like that. Thanks for reading this and I hope that someone will help me !


let c = document.createElement("canvas")
let img1 = new Image()

img1.onload = function() {
    document.getElementById("img1").remove()
    w = img1.width
    h = img1.height

    c.width =  w
    c.height = h
    ctx = c.getContext("2d")
    ctx.drawImage(img1, 0, 0,)

    let pixelarr = ctx.getImageData(0,0,w,h).data
    let samplesize = 10
    
   

  
    for(let y=0;y<h;y+=samplesize)
        for(let x=0;x<w;x+=samplesize) {
            let p = (x+(y*w))*4
            ctx.fillStyle = "rgba(" + pixelarr[p] + "," + pixelarr[p+1] + "," + pixelarr[p+2] + "," + pixelarr[p+3] + ")"
            ctx.fillRect(x,y,samplesize, samplesize)
        }

    

    let img2 = new Image()
    img2.src = c.toDataURL("img/jpeg")
    img2.width = 600
    document.body.appendChild(img2)

  
    }
    

img1.src = document.getElementById("img1").src
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda