java applet screenshot

Discussion in 'Java' started by antoine c., Aug 12, 2004.

  1. antoine c.

    antoine c. Guest

    dear experts,

    i am wondering if this simple screenshot.java program, developed by
    Marco Schmidt could be ported as a applet?

    I would like to port such a program as an applet i.e. take a
    screenshot of the web user's browser's front window, get the picture
    transferred and written on the server side and email the resulting
    image back to the web user. My aim is also that all the whole process
    remains painless for the user.

    My question: do you know if such an implementation the current program
    is possible? Is it possible to send the BufferedImage image =
    robot.createScreenCapture() and write it on the server side? Would any
    restrictions occur, or certificate need to be established?

    You would save me all a lot of time if you could answer the question.

    for a complete link to the following code, please take a look at:
    http://www.geocities.com/marcoschmidt.geo/java-save-screenshot.html


    /*
    * Screenshot.java (requires Java 1.4+)
    */

    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;

    public class Screenshot {
    public static void main(String[] args) throws Exception {
    // make sure we have exactly two arguments,
    // a waiting period and a file name
    if (args.length != 2) {
    System.err.println("Usage: java Screenshot " +
    "WAITSECONDS OUTFILE.png");
    System.exit(1);
    }
    // check if file name is valid
    String outFileName = args[1];
    if (!outFileName.toLowerCase().endsWith(".png")) {
    System.err.println("Error: output file name
    must " +
    "end with \".png\".");
    System.exit(1);
    }
    // wait for a user-specified time
    try {
    long time = Long.parseLong(args[0]) * 1000L;
    System.out.println("Waiting " + (time / 1000L)
    +
    " second(s)...");
    Thread.sleep(time);
    } catch(NumberFormatException nfe) {
    System.err.println(args[0] + " does not seem
    to be a " +
    "valid number of seconds.");
    System.exit(1);
    }
    // determine current screen size
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    Rectangle screenRect = new Rectangle(screenSize);
    // create screen shot
    Robot robot = new Robot();
    BufferedImage image =
    robot.createScreenCapture(screenRect);
    // save captured image to PNG file
    ImageIO.write(image, "png", new File(outFileName));
    // give feedback
    System.out.println("Saved screen shot (" +
    image.getWidth() +
    " x " + image.getHeight() + " pixels) to file
    \"" +
    outFileName + "\".");
    // use System.exit if the program hangs after writing
    the file;
    // that's an old bug which got fixed only recently
    // System.exit(0);
    }
    }


    thank you,

    antoine
     
    antoine c., Aug 12, 2004
    #1
    1. Advertising

  2. "antoine c." <> wrote in message
    news:...
    > dear experts,
    >
    > i am wondering if this simple screenshot.java program, developed by
    > Marco Schmidt could be ported as a applet?
    >
    > I would like to port such a program as an applet i.e. take a
    > screenshot of the web user's browser's front window, get the picture
    > transferred and written on the server side and email the resulting
    > image back to the web user. My aim is also that all the whole process
    > remains painless for the user.
    >
    > My question: do you know if such an implementation the current program
    > is possible? Is it possible to send the BufferedImage image =
    > robot.createScreenCapture() and write it on the server side? Would any
    > restrictions occur, or certificate need to be established?


    I would think at the very least it would be (or should be) some kind of
    security violation for an untrusted applet to get a full screen shot. I
    think "CanvasAccess" or possibly "UniversalTopLevelWindow" privileges would
    be required. If you can get the user to agree to that privilege, however
    (by requesting it with a signed applet), everything else should work
    (presuming you're sending the image back to the original server. Saving it
    as a file is another privilege.)

    Cheers,
    Matt Humphrey http://www.iviz.com/
     
    Matt Humphrey, Aug 12, 2004
    #2
    1. Advertising

  3. On 12 Aug 2004 11:56:09 -0700, antoine c. wrote:

    > i am wondering if this simple screenshot.java program, developed by
    > Marco Schmidt could be ported as a applet?


    Applets operate within a tighter security
    sandbox than applications, but once the
    security restrictions are relaxed, thet
    can achieve anything an application can..

    > I would like to port such a program as an applet i.e. take a
    > screenshot


    And that is definitely an activity that will
    require the code to be jar'd and signed. Then,
    if the user agrees to accept the code, it can proceed.

    >..of the web user's browser's front window, get the picture
    > transferred and written on the server side


    Would require JSP/Servlets or some other
    server side support..

    >..and email the resulting
    > image back to the web user.


    What is the point of the round trip to the server?
    Does this entire process have an advantage over
    a short page describing this* key and it's effects..
    <http://www.physci.org/kbd.jsp?key=prt>

    And, ..why exactly does the user want a
    screenshot of your web-page?

    >My aim is also that all the whole process
    > remains painless for the user.


    Accepting a signed applet and fessing up an
    email address to the author seems more painful
    than doing a 'print screen' somehow..

    > My question: do you know if such an implementation the current program
    > is possible?


    Possible, yes, though I still do not quite
    get the point of what you are trying to achieve.

    [ F'Ups set to c.l.j.gui. 'cos my newsreader
    whines at me if I do not set F'Ups.. ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Aug 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron

    screenshot

    Aaron, Oct 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    598
    Scott
    Oct 6, 2004
  2. Paul Aspinall

    Click to see full size screenshot

    Paul Aspinall, Mar 20, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    313
    Brock Allen
    Mar 20, 2005
  3. Krista
    Replies:
    3
    Views:
    2,321
    Andrew Thompson
    Sep 15, 2004
  4. Luigi Donatello Asero

    Re: Please criticize my website.: with screenshot

    Luigi Donatello Asero, Oct 4, 2005, in forum: HTML
    Replies:
    1
    Views:
    330
    dorayme
    Oct 4, 2005
  5. George Weis
    Replies:
    2
    Views:
    1,335
    John B. Matthews
    Feb 23, 2010
Loading...

Share This Page