Get pixel color from running app

Hello, I am really new, so sorry for stupid question.
I need get pixel color from window of running app - something like getPixel(window_coord_x, window_coord_y). Robot does not work, it is not for actual running window

Can you describe how this is a JME question?

I got project with “class Main extends SimpleApplication” and now I need (when the app is running) get color of some pixel in window. I assume there is some way how get color buffer, Graphics or something like that, isn’t it?

@saidllen said: I got project with "class Main extends SimpleApplication" and now I need (when the app is running) get color of some pixel in window. I assume there is some way how get color buffer, Graphics or something like that, isn't it?

Sort of.

You have to copy the whole frame buffer from the graphics card to regular memory and then look for the pixel you want. 9 times out of 10, this is not really what you want to do since it’s a long way to go just to get a pixel color.

Why do you need this?

I have a model rendered on the screen and I have an image of the model in different position. What I need is - count a differences over a neighbourhood at a given coordinates between screen and image (block matching alg) so I need a color of pixel on the screen

But not just one pixel… you need a bunch of pixels.

Look at the ScreenshotAppState source code. It will show you how to copy the frame buffer into a place you can use it.

1 Like

Maybe you should look at the example that renders a scene to a texture. Forgot its name.
It does what you want : get a ‘bitmap’ of a rendered scene.

Next you could use something like ImageRaster to read colors from it.

Edit : You also have the screenshot app-state…

ReEdit : Oops too slow, once again. I Should hit refresh before answering !

1 Like