1

I have been messing around with re-sizing arrays of pixels. I have managed to make some code that scales up the pixels when they are rendered. The problem with the code is that I can only scale the pixels up with whole numbers (1, 2, 3, etc.). I want to be able to scale the pixels up using a double (.001, .002, etc) so I am not restrained to only a few image sizes. Here is the code I wrote:

public void draw(Sprite s, int xCord, int yCord, int scale){
    for(int y = 0; y < s.getHeight()*scale; y++){
        for(int x = 0; x <s.getWidth()*scale; x++){
            pixels[(x+xCord) +(y+yCord)*this.width]
                = s.pixels[(x/scale+ y/scale * s.getWidth())];
        }       
    }
}

Can this be easily tweaked to allow for non-whole number scales?

The class Sprite knows its own width and height given by s.getWidth() and s.getHeight(). The height and width are the actual dimensions in pixels of the .png when it was read.

jordanhill123
  • 4,142
  • 2
  • 31
  • 40
Sock314
  • 157
  • 9
  • Not very easily, no, and you're going to end up with blurry results. If you want to go ahead anyway, think about it as having a grid of colors superimposing a finer grid, and looking at the results of that finer grid. You will have to take a weighted average of 2 or 4 pixels for at least some of the pixels. – raptortech97 Oct 02 '14 at 01:31

1 Answers1

1

For flexibility in choosing the resampling algorithm, use AffineTransformOp, as shown here, or just let the graphics context handle it, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045