I am currently making a paint like program with Java Applets. I want to simulate a bucket tool by using recursion and checking each pixel around a given point, however I am having trouble getting the RGB value at a given pixel.
Is there a way to do something such as
public void paint(Graphics g) {
g.getPixelAt(X, Y);
}
Or something?
Graphicsis virtual concept and does not support what you are trying to doWhat you need to do is paint to a surface that you can interact with, something like a
BufferedImage.The basic idea would be painting all effects to this buffered image and using
Graphihcs#drawImageto actually render the image to the screen.From there you can us
BufferedImage#getRasterwhich will provide you with aWritableRasterobject which hasget/setPixelmethods.