Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links


Capturing a Screenshot in Awt

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-02-2010
Level8's Avatar
Member
 
Join Date: Nov 2009
Posts: 871
Capturing a Screenshot in Awt

Sponsored Links
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.

Reply With Quote
  #2  
Old 17-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,943
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();
}
    }
}
Reply With Quote
  #3  
Old 17-02-2010
Member
 
Join Date: May 2008
Posts: 2,000
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) 
{ 
}
Reply With Quote
  #4  
Old 17-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,990
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.
Reply With Quote
  #5  
Old 17-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,278
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"));
Reply With Quote
  #6  
Old 17-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,382
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Capturing a Screenshot in Awt"
Thread Thread Starter Forum Replies Last Post
Is it possible to capturing on-screen pictures with HTC HD2 Sosie Portable Devices 5 27-04-2011 07:36 PM
How to take a Screenshot on the iPad and iPhone without a screenshot application Emily123 Tips & Tweaks 2 21-07-2010 05:14 AM
Capturing Program? alex198555 Windows Software 1 12-07-2010 11:06 AM
about capturing video what can i do?? Vista Help 8 09-08-2009 10:29 PM
Capturing Images From Wmv Video Akshita Windows Software 3 02-06-2009 09:38 PM


All times are GMT +5.5. The time now is 12:34 PM.