0

is there a way to get the content of the current Buffer im writing to? a sort of a representation of what i've written to its graphics. For example, in the following code, i would like to get a BufferedImage or even an Array that has values that represent what i've written, in this case; a black background and a white rectangle:

public static void render (Canvas canvas) {
        BufferStrategy buffer = canvas.getBufferStrategy();
        Graphics g = buffer.getDrawGraphics();
        
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

        g.setColor(Color.WHITE);
        g.drawRect(50, 50, 100, 100);   

        g.dispose();
        // Maybe a method here that allows me to get what has been writen?
        buffer.show();                  
    }

Thanks in advance!

telos
  • 25
  • 6
  • 1
    Generally, no. If you wanted this kind of feature, then you'd need to make it yourself. Remember in this case, you're using a "page flipping" process, where there is a "presented" buffer and then a series of "off screen" buffers. You write to the off screen buffer(s) and then request that it be made the "presentation" buffer – MadProgrammer Feb 23 '22 at 00:04
  • @MadProgrammer Alright, thank you. I'll post it here if i end up creating it. – telos Feb 23 '22 at 00:32

0 Answers0