开发者

Scaling a bitmap in to another bitmap, best 'manual' way?

开发者 https://www.devze.com 2023-04-02 01:13 出处:网络
The bitmap is nothing more then a int[] pixels = new int[width * height]; I am using in this way: BufferedImage img = new BufferedImage(WIDTH,HEIGHT,RGB);

The bitmap is nothing more then a int[] pixels = new int[width * height];

I am using in this way:

BufferedImage img = new BufferedImage(WIDTH,HEIGHT,RGB);
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();

'do rendering here on pixels[], for instance load an image using BufferedImage img = ImageIO.read(URL);

Graphics g;
g.drawImage(img, 0,0, getWidth(), getHeight(), null);

Now during the 'do rendering here on pixels' lots of stuff can happen, coloring the textures (they are gray-scales) but I also need to rescale them. Though I don't know "the best way" to do this.

All 'bitmaps' are just an array of ints.

Scaling can be done in steps on 0.1 or 0.01 or 3. I personally thought something like:

for(int yy = 0; yy < tex.height; yy++){
    fo开发者_如何学Cr(int xx = 0; xx < tex.width; xx++){
        int px = tex.getPixel(yy * tex.width + xx);
        this.putPixel( (y*this.width)+((int)((yy*scale) * tex.width)) + (x) + ((int)(xx*scale)));
    }
}

But I have no clue if this would be 'the right' way. Or if there are other/better ways.


Sadly there is no right way. You have to make a trade-off between quality and performance.

The wikipedia page on image scaling has a good overview of methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号