Is there another drawImage(lithosphere, 0, 0, null); command somewhere in your code?

If so, maybethat other drawImage is the only one actually displaying. This could occur for a number of reasons, for example, if the EDT is "collapsing" draw commands, or if the Graphics2D parameter you are passing is somehow not connected to the displaying component (JPanel? JComponent? Canvas?) or that component is not getting a repaint() or equivalent.

One idea for testing, simply make a very different graphic and make your code thus:

1 2 3 4 5 6 7

privatevoidrender(Graphics2Dg2d){

lithosphere = testImage; // testImage is an image that is obviously different

g2d.drawImage(lithosphere, 0, 0, null);

}

If the testImage displays, then you KNOW it is a problem with the WritableRaster code. But I'm starting with the assumption it is not, since you said you inspected the graphic and confirmed that it IS changing.

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

The raster is changing but when I go to draw the image nothing is drawn. The image stays the same. Any ideas?

I don't see any obvious problems with the code. Can you produce a minimal self-contained (i.e. compilable and runnable with just the standard API for dependencies) program which demonstrates the same problem?

No, that is the only place in which the image is being rendered. Also the image is being drawn onto a JPanel. The Graphics2D device is passed by the JPanel's paintComponent(Graphics g) method. Which is shown below.

The funny thing about it is if I fill a rectangle onto the image in the start before any changes are made, say a red box, it renders that just fine. But no changes are being made to the raster.

A couple of the issues that I mentioned could still be causing the problem, even if there is just the one imageDraw.

Here's another idea: put in a System.out.println() message every time render gets called, just to make sure it is getting called multiple times.

Also, can you show us the calling code and where you repaint() the JPanel? Changing the graphic does nothing unless you redisplay the JPanel. It may not be called, or it may be a call that is getting collapsed by the EDT.

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

The bug was serveral things. The for-loops WIDTH and HEIGHT conditions were not set correctly and were giving false states. As for the WritableRaster, the code below is what now works. Strange, you have to set the data in the buffered image you are currently working on. Apparently the reference is a copy so I was not working directly on the image.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org