aspose file tools*
The moose likes Applets and the fly likes How to Save applet page as a JPG file  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "How to Save applet page as a JPG file  " Watch "How to Save applet page as a JPG file  " New topic
Author

How to Save applet page as a JPG file

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Hello,

How to Save applet page as a JPG file ?

Thanking You.


Thank You<br />Edward
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
The java.awt.Robot.createScreenCapture method can take screenshots, but the applet would need to be signed to be allowed to do this.


Ping & DNS - my free Android networking tools app
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Hello Sir,

Thanks for your mail. Actually I am doing Web application.

My application have installed in the server machine.

I have accessed this application in the another(client) system.

When I click save screen button, i can create the .jpg screen. but it looks

server system .jpg screen but not in my client screen.

1) How can capture client system image (.jpg) screen
2) How can store that .jpg file in the client system.

Thanking You.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
I'm confused. Isn't the "Save" button -as well as the code doing the screenshot- part of the applet? Where does a web application enter the picture?
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Actually I have one Applet Graph. under the applet I have html save button. When I click the html save button, the entire screen of the Graph page should be stored as a image (.jpg) file.

That's all. It's working in server machine(application installed machine).

But when i access graph page in the other machine (client), and click the html save button, but it shows the server system desktop screen shot. Hope you understand. Because application is running in the server system.

Please let me know if you a doubt.

if you have any other way, please tell me

Thanking You.
Regards,
Edi
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
If you want to take a screenshot of the client system, then obviously the code to do so must be running on the client, not the server. So I'd say you need to move that code into the applet.
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
try{
BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
// Save as JPEG
File file = new File("c:/report_image_format.jpg");
ImageIO.write(screencapture, "jpg", file);

}catch(Exception e)
{
LOG.info("Screen Capture Error : "+e);
}

This is a applet code. right?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
That's Java code.

It can run in an applet if you put it there. But you seem to have put it into the server code (where GUI code really has no place, because nobody will see it).
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Hello Sir,

My Graph is a applet. If I create one applet button. And in it's clicking action, can I put that codes?

if i put these codes in applet, Client machine can get their own system graph jpg file?

Thanking You.
Regards
Edi
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Yes. See my first post in this thread.
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
thanks for your mail.

where can i find your first thread regarding this?

And please tell me any other way to get screen shots (.jpg) file in client machine using other than applet?

thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
where can i find your first thread regarding this?

Not first thread - my first post in this thread. You can find it closer to the top of the screen
[ April 25, 2008: Message edited by: Ulf Dittmer ]
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
in the applet button click, i have tried, but i am not able save the jpg file in my local system. how?

my code looks like

public void actionPerformed(ActionEvent event) {
label.setText(waitingMessage);
if(event.getSource() == button)
{
System.out.println("cancel button clicked...");
try{
// capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );

// Save as JPEG
File file = new File("c:/screencapture.jpg");
ImageIO.write(screencapture, "jpg", file);
System.out.println("screen capture finished : ");
}catch(Exception e)
{
System.out.println("screen capture error : ");
}


}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
What does "not able" mean? What happens when you run the code you posted? If there are exceptions, tell us which ones, and in which lines they occur. Right now, the code throws away all information about exceptions that would help debug the issue - add an "e.printStackTrace()" to the exception handler.
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
hello,

that jpg file not created in my local system.

i have tried "e.printStackTrace()" also. But i am not getting any error.

when i run the applet code in command prompt, the jpg file created in my local system.

but when i put the applet code in the webpage, the jpg file have not created.

Please give me your suggestion.

thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
So you're actually seeing "screen capture finished" being displayed, but no file is created?
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Yes. You are Correct. File have not created.

Please send me your suggestion.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Are you seeing "screen capture finished" being displayed?

If not, then you must see "screen capture error". In that case, print out the exception information, so that you know what the problem is.
[ May 14, 2008: Message edited by: Ulf Dittmer ]
Jaffer Sadiq
Greenhorn

Joined: May 19, 2008
Posts: 24
Hi,
try{
// capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );

// Save as JPEG
File file = new File("c:/screencapture.jpg");
ImageIO.write(screencapture, "jpg", file);
System.out.println("screen capture finished : ");
}catch(Exception e)
{
System.out.println("screen capture error : ");
}
}

--> This program will capture final out come of the applet sceen....

Thanks,
Jaffer
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Jeffer, how is the code you posted different from the one Edward posted before?
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
any solutions or suggestions please?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
any solutions or suggestions please?

In my post on 5/14 I asked a couple of questions. Without knowing the answers to those I don't know what else to tell you.
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
i got only screen capture finished only. i did not get any error messages using - printstack trace.

please advise.

any reply...
[ August 03, 2008: Message edited by: Edward Durai ]
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
please advise regarding the above problem

thanks
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
hello Ulf Dittmer,

are you there?

any help....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
My guess would be that the file is being created, just not in the location where you expect it to be. Is "c:/screencapture.jpg" a valid filename in the root directory? Meaning, if you use it with this code in an application (not an applet), does a file get created in the root of the C: drive? Assuming, of course, that you run the application in a directory other than the C: root directory.
[ August 14, 2008: Message edited by: Ulf Dittmer ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to Save applet page as a JPG file