kikiotsuka
kikiotsuka

Reputation: 79

Color at Certain Pixel location inside Java Applet?

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?

Upvotes: 0

Views: 1208

Answers (2)

Jon Hulka
Jon Hulka

Reputation: 1309

You could use Applet.getLocationOnScreen() and java.awt.Robot.createScreenCapture() to find and capture the part of the applet you want.

This question poses a similar problem.

Upvotes: 1

MadProgrammer
MadProgrammer

Reputation: 347204

Graphics is virtual concept and does not support what you are trying to do

What 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#drawImage to actually render the image to the screen.

From there you can us BufferedImage#getRaster which will provide you with a WritableRaster object which has get/setPixel methods.

Upvotes: 2

Related Questions