位圖只不過是一個int[] pixels = new int[width * height]
;將位圖縮放到另一個位圖中,最好採用「手動」方式?
我使用了這種方式:
BufferedImage img = new BufferedImage(WIDTH,HEIGHT,RGB);
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
「就在這裏呈現的像素[],例如加載使用BufferedImage img = ImageIO.read(URL)
的圖像;
Graphics g;
g.drawImage(img, 0,0, getWidth(), getHeight(), null);
現在在「做渲染在這裏像素」很多東西都可能發生,着色紋理(它們是灰階),但我還需要重新調節。雖然我不知道「最好的方式」做到這一點。
所有'位圖'只是一個整數數組。
縮放可以在步驟來完成對0.1或0.01或3 我個人認爲是這樣的:
for(int yy = 0; yy < tex.height; yy++){
for(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)));
}
}
但我不知道這是否會是「正確」的方式。或者如果有其他/更好的方法。
如果需要更多信息,請不要問。 –
參見'AffineTransformOp',顯示[here](http://stackoverflow.com/questions/4216123/how-to-scale-a-bufferedimage/4216635#4216635)。 – trashgod
是的,我看到了一個,但我不打算保留對BufferedImage對象的引用。 –