Results 1 to 5 of 5
  1. #1
    venkatendra is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default every 10 min Capture a Screenshot in Java program

    Hi All,
    Im using the below program Capture a Screenshot in java program and connect to the database and store the Capture a Screenshot image in database.

    but Iwant every 10 min randomly taken Capture a Screenshot in Java program and connect to database store the Capture a Screenshot image.

    can we provide the related example code. please help.....


    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.sql.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import java.sql.Timestamp;


    public class JavaScreenCaptureUtil {

    public static void writeImage(BufferedImage img, String fileLocation,
    String extension) {
    try {
    BufferedImage bi = img;
    File outputfile = new File(fileLocation);
    ImageIO.write(bi, extension, outputfile);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static String createTimeStampStr() throws Exception {
    Calendar mycalendar = Calendar.getInstance();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_hhmmss");
    String timeStamp = formatter.format(mycalendar.getTime());
    return timeStamp;

    }

    public static void main(String args[]) throws Exception {

    Robot robot = new Robot();
    BufferedImage bi = robot.createScreenCapture(new Rectangle(1000, 700));
    String fileNameToSaveTo = "C:/image_" + createTimeStampStr()+ ".PNG";
    writeImage(bi, fileNameToSaveTo, "PNG");

    Connection connection = null;
    PreparedStatement psmnt = null;
    FileInputStream fis;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    String connectionURL = "jdbc:mysql://localhost:3306/discoff";
    connection = DriverManager.getConnection(connectionURL, "root", "");
    File image1 = new File(fileNameToSaveTo);
    psmnt = connection.prepareStatement("insert into saveimage(id,image,datetime) values(?,?,?)");
    psmnt.setInt(1, 1);
    fis = new FileInputStream(image1);
    psmnt.setBinaryStream(2, (InputStream) fis, (int) (image1.length()));
    psmnt.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
    int s = psmnt.executeUpdate();
    if (s > 0) {
    System.out.println("Uploaded successfully !");
    } else {
    System.out.println("unsucessfull to upload image.");
    }
    }
    catch (Exception ex) {
    System.out.println("Found some error : " + ex);
    } finally {
    connection.close();
    psmnt.close();
    }

    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: every 10 min Capture a Screenshot in Java program

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: every 10 min Capture a Screenshot in Java program

    Copying code from the net rarely helps, unless you take the time to learn enough Java to understand what the code actually does.

    It's also unethical to post someone else's code on a public forum without attributing it to its original author.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: every 10 min Capture a Screenshot in Java program

    And, it's extremely unethical to abandon a forum thread and start another with the same question.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: every 10 min Capture a Screenshot in Java program

    Cross posted on the floral subcontinent site that we don't like to name because of their really, really bad content.
    http ://www.[removed].net/answers/viewqa/Java-Beginners/25264-how-can-write-the-program-for-every-10-min-randomly-taken-Capture-a-Screenshot-in-Java-program-and-connect-to-database-store-the-Capture-a-Screenshot-image-.html

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Taking a screenshot and redisplaying it
    By aprop in forum New To Java
    Replies: 3
    Last Post: 03-03-2012, 10:24 PM
  2. Replies: 2
    Last Post: 05-22-2011, 09:56 AM
  3. Replies: 3
    Last Post: 05-03-2011, 04:24 AM
  4. Capturing a screenshot of a another pc?
    By chyrl in forum Advanced Java
    Replies: 9
    Last Post: 06-08-2010, 06:07 PM
  5. Get screenshot(picture) of own pc
    By shekhar2010 in forum New To Java
    Replies: 5
    Last Post: 01-24-2010, 04:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •