Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda