An easy task----how to make a camera view to a Image?

dude, put a condition in your getRGBColor() to check if the image exists:



[java]

if(file.exist()){

//read the image properties here

}

[/java]

I tried also this, but the file doesn’t exist, but when i close the application the image has been saved. so i think that it can’t open the image immediatly after it has made the screen shot.

So are you saying that the image is only saved when the application finishes?

Not really, the only solution i’ve found so far is to control the aquisition of the screen shot and the call to getRGBColor with two different key, so i press a key for get screen shot and it saves the image, then i press an other key and i get the pixel color. the problem is that i must do the two thing with only one key.

Anyone have any idea? please i don’t know how to solve this problem

onAction is called in the update loop and the screen shot is generated post render loop, so when you do state.onAction(null,true,0); the AppStage does not generate the image instantly. And will be available only on next update loop

What you should do is set a boolean to true in the onAction, then in the update loop check for this boolean an if it’s true call your getRGBColor

like this

[java]

private boolean captureDone = false;

public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals(“ScreenShot”) && keyPressed) {

state.onAction(null,true,0);

captureDone = true;

}

}



public void simpleUpdate(float tpf){

if(captureDone){

getRGBColor(400,300);

captureDone = false;

}

}

[/java]

Thank you for your help, but just that code? or I need to change other things? because I tried but it still throws the exception:

“javax.imageio.IIOException: Can’t read input file!”

So you are trying to write a file of the screen just to load it again and get a pixel color? You don’t need the file for any other reason?



That’s the loooong way to go to get the pixel color at a location on the screen.

I need to know the color of any points in space framed by the camera, so I calculated the equivalent points on the screen and then with screen shot I thought to get the color of that point, is there another way?

The screen shot app state turns the screen into an image and then writes that image to a file. If all you needed was the image then you are doing way more work than you needed when you could have just copied screen shot app state to get the screen capture part and then you’d have the image right there. No reason to involve the hard disk at all.

Iìm sorry but I have not found a way to get the image, how do I copy it from ScreenshotAppState? I use a framebuffer?

I meant copy the code. You have all of the code of JME available to you.

I looked at the class ScreenshotAppState and I tried this code:

[java]

RenderManager rm = new RenderManager(renderer);

renderer = rm.getRenderer();

ByteBuffer outBuf = BufferUtils.createByteBuffer(cam.getWidth()*cam.getHeight()*4);

awtImage = new BufferedImage(cam.getWidth(), cam.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);

renderer.readFrameBuffer(imageFrame, outBuf);



Screenshots.convertScreenShot(outBuf, awtImage);

getRGBColor(400,300,awtImage);

[/java]



but I can not figure out how to create the FrameBuffer ImageFrame (which is FrameBuffer out, in the class ScreenshotAppState), from which to read

It’s all right there in that class, you just have to copy more of it including being a scene processor, etc… it’s all important.



It occurs to me that this may be too hard for you to do on your own. You might need to see if you can find a Java developer to help you more directly.

i know and i’m sorry, but I have to deliver this project in a short time and somehow I’ve got to do it

For work or for school?

For school

Copy screen shot app state… the whole thing. Give it a new name.



Instead of saving the image to disk have it just set it to a field on the class. Have it do that every frame… don’t bother turning it on and off.



Add a get method for the image that you’ve tucked away.



Then your code that needs the image, it can just grab the app state and use that getter to get the image. Getting a pixel color from the image shouldn’t be hard and is not a JME specific problem, anyway.

I apologize for the many questions.

Thank you very much for the help; now it all works, thanks again