how to get screen shot in Java

View previous topic View next topic Go down

how to get screen shot in Java

Post by BIT0112-Rokon on Tue Aug 10, 2010 9:59 pm

Guys,
Today I'm going to share a very interesting tip of Java. Some time we need to have screen shot. It is quite easy in Java. Okay, lets see how to make it possible with Java. There is a interesting class in Java named Robot.java. You know, programming is kind of fun. so the name robot makes some fun for you. better get some knowledge from here

okay guys, let see the code..

Code:

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
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 {
           //lets get the screen size
            Dimension size = Toolkit.getDefaultToolkit().getScreenSize();           
            Robot robot = new Robot();
            // Capture the screen shot of the area of the screen defined by the rectangle
            BufferedImage bi=robot.createScreenCapture(new Rectangle(new Dimension(size)));
            // set the image formate and directory of the image where it will be available
            ImageIO.write(bi, "png", new File("/home/rokon/Desktop/screenshot.png"));
           
        } catch (AWTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

okay guys, now compile and run it.

cheers!!!!!

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: how to get screen shot in Java

Post by BIT0104-ANIK on Wed Aug 11, 2010 12:03 am

what would be the output..if i wanna run it, i must me clicking it. when i need to take screenshot of some other application window, then it would have been helpful to have a keyboard shortcut. Can you manage this?

_________________________________________________________________
Buddhong shoronogocchami..
dhommong shoronogocchami..
shonghong shoronogocchami..
Jogoter sokol prani.. shukhi hok.
avatar
BIT0104-ANIK
Administrator
Administrator

Course(s) :
  • BIT

Blood Group : O+
Posts : 423
Points : 699

View user profile http://anikstech.blogspot.com

Back to top Go down

Re: how to get screen shot in Java

Post by BIT0112-Rokon on Wed Aug 11, 2010 12:06 am

okay.. I'll try if it is possible by me .. btw you guys can try it....

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: how to get screen shot in Java

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum