Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!