Results 1 to 6 of 6

Thread: Capturing a Screenshot in Awt

  1. #1
    Join Date
    Nov 2009
    Posts
    862

    Capturing a Screenshot in Awt

    Hello, I am creating my project with the help of java. And I have selected awt for creatinig it. But, I am now confused about one problem, as I am not having any information from which I can able to get the screenshot of the page. If you are having any idea from which I can achiev it, then please provide help me to achieve it. Thank you in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Capturing a Screenshot in Awt

    Hello, I have the code below which can simply help you for taking the screenshot of the screen which you want.

    Code:
    import java.awt.AWTException;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    
    public class Screenshot 
    {    
    public static void main(String[] args) 
    {        
    try
    {            
    Robot robo = new Robot();
    BufferedImage bufferedIm=robo.createScreenCapture(new Rectangle(100,100));
    ImageIO.write(bufferedIm, "jpg", new File("C:/img.jpg"));
    } 
    catch (AWTException e) 
    {
    e.printStackTrace();
    } 
    catch (IOException e) 
    {
    e.printStackTrace();
    }
        }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Capturing a Screenshot in Awt

    Hello, if you make use of the code below then you will able to get the solution for your problem for getting the screenshot in jpg format. So, just make use of it and solve your problem.
    Code:
    try 
    {
    Robot rbt = new Robot(); 
    int num = 100; 
    int num1 = 100; 
    int wdth = 200; 
    int hght = 200; 
    Rectangle rectarea = new Rectangle(num, num1, wdth, hght); 
    BufferedImage buffImage = rbt.createScreenCapture(rectarea); 
    rectarea = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); 
    buffImage = rbt.createScreenCapture(rectarea); 
    } 
    catch (AWTException e) 
    { 
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Capturing a Screenshot in Awt

    Hello, if you want to capture the screen with the help of java awt then you must need to make use of the trick of the Print screen in our windows application. For getting the solution for your problem you must need to make use of the methods below:
    createScreenCapture():
    If you make use of this method then you are using the method of the Robot class. This methd will create an image which can be read by the screen. For getting the screen size it make uses the getDefaultToolkit().getScreenSize() method of the Toolkit class.

    write():
    write() is the method of the ImageIO class. Image is saved into the image buffer before creating the new image. If you are using this method then it is necessary to make use of the three arguments below:
    • rendered image
    • file format
    • output file name


    ImageIO:
    it is the class which is available in javax.imageio.*; package. It will help you to read the image.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Capturing a Screenshot in Awt

    Hello, if you want to capture the screenshot in Awt then you just need to make use of the code below in your program and you will able to get solved your problem:
    Code:
    Robot robot = new Robot();
    BufferedImage bufferedimage=robot.createScreenCapture(new Rectangle(250,400));
    ImageIO.write(bufferedimage, "jpg", new File("C:/img.jpg"));

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Capturing a Screenshot in Awt

    Hello, for getting this problem solved you must need to make use of the following books in AWT:
    • Java AWT Reference
    • The Java Language Specification
    • The Java Programming Language, 2nd Edition
    • Advanced Java Networking

Similar Threads

  1. Replies: 5
    Last Post: 27-04-2011, 07:36 PM
  2. Replies: 2
    Last Post: 21-07-2010, 05:14 AM
  3. Capturing Program?
    By alex198555 in forum Windows Software
    Replies: 1
    Last Post: 12-07-2010, 11:06 AM
  4. about capturing video
    By what can i do?? in forum Vista Help
    Replies: 8
    Last Post: 09-08-2009, 10:29 PM
  5. Capturing Images From Wmv Video
    By Akshita in forum Windows Software
    Replies: 3
    Last Post: 02-06-2009, 09:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,483,155.50664 seconds with 17 queries