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

112
Visualizações
Pixelate animation

I'm trying to pixelate an animation.. I have a .png image where I cut in frames. I have a scrollbar who gives a number, which is the new size of every pixel. (rasterSize) I already did it for an image and it's working. http://bht-homework.com/RMA/PIX_PRES1/

But for animation it looks like doesn't calculate the first pixels. http://bht-homework.com/RMA/PIX_PRES2/

           var imgData=context.getImageData(0,0,img.width,img.height);// width is 190,height 240
            for (var x = 0; x < spriteSizeWidth; x++) {
                for (var y = 0; y < spriteSizeHeight; y++) {
                
                     var rasterX = ((x / rasterSize) | 0) * rasterSize;
                     var rasterY = ((y / rasterSize) | 0) * rasterSize;

                     var rasterValIndex = (rasterX + rasterY * imgData.width) * 4;

                     r=imgData.data[rasterValIndex];
                     g=imgData.data[rasterValIndex + 1];
                     b=imgData.data[rasterValIndex + 2];
                     a=imgData.data[rasterValIndex + 3];
               
                
                    context.fillStyle="rgba(" +r+","+g+","+b+","+a+")";
                    context.fillRect(x,y,rasterSize,rasterSize);
                }
          }
                

Does someone has an idea how to fix it? Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Though it might look as it would skip the first few pixels of your image, it actually just draws the blocks at the wrong position. It's offset by rasterSize.

You need to shift back the pixels to the correct position.

So simply replace

context.fillRect(x, y, rasterSize, rasterSize);

by

context.fillRect(x - rasterSize, y - rasterSize, rasterSize, rasterSize);
about 4 years ago · Juan Pablo Isaza Relatório
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