My method wasn’t intended to be used every frame. It’s just a quick way to copy pixels from one image to another, without dealing with volatile images / video memory / etc.
You’ve changed your questions so many times that I’m no longer really sure what your current problem is or what you’re trying to accomplish…
[quote]I’m trying to do pixel-by-pixel rendering to an image using for loops. I have an int array where pixel data is written to, and then, once per frame, that array is rendered to the BufferedImage.
[/quote]
BufferStrategy s = getBufferStrategy();
if (s == null) {
createBufferStrategy(2);
}
for (int i = 0; i < pixels.length; i++) {
pixels[i] = i + (int)System.currentTimeMilllis();
}
drawImageAt(10, 20, someImage);
Graphics g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
bs.show();
public void drawImageAt(int x, int y, BufferedImage img) {
int[] pixies = img.getRGB(0,0, img.getWidth(), img.getHeight(), null, 0, img.getWidth() );
for (int yy = 0; yy < img.getHeight(); yy++) {
for (int xx = 0 ; xx < img.getWidth(); xx++) {
pixels[ (y+yy) * image.getWidth() + x + xx ] = pixies[y*img.getWidth() + x];
}
}
}