Capture the current screen image.
Hope to have more communication. 8 -)
Package com. borland. samples. welcome;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @ Author
* @ Version 1.0
*/
Import java. awt .*;
Import java. awt. image .*;
Import com.sun.image.codec.jpeg .*;
Class ImageCanvas extends Canvas {
Private Image image;
Private Dimension prefSize;
Public ImageCanvas (Image image ){
This. image = image;
CalculatePreferredSize ();
}
Public void setImage (Image image ){
This. image = image;
CalculatePreferredSize ();
Repaint ();
}
Private void calculatePreferredSize (){
PrefSize = new Dimension (image. getWidth (this), image. getHeight (this ));
System. out. println (image. getWidth (this ));
SetSize (prefSize );
}
Public Dimension getPreferredSize (){
Return prefSize;
}
Public Dimension getMinimumSize (){
Return prefSize;
}
Public void update (Graphics g ){
Paint (g );
}
Public void paint (Graphics g ){
G. drawImage (image, 0, 0, null );
}
}
Class ImageUtils {
Public static Image getScreenImage (){
Robot robot;
Try {
Robot = new Robot ();
} Catch (Exception e ){
Throw new RuntimeException ("unable to construct Robot ");