ImageIO.write(getPickedImage(),"png",file);
}
/**储存为一个JPEG格式图像文件*/
public void saveAsJPEG(File file) throws IOException {
ImageIO.write(getPickedImage(),"JPEG",file);
}
/**写入一个OutputStream*/
public void write(OutputStream out) throws IOException{
ImageIO.write(getPickedImage(),defaultImageFormater,out);
}
//singleton design pattern
private static ScreenCapture defaultCapturer = new ScreenCapture();
private int x1,y1,x2,y2;
private int recX,recY,recH,recW; //截取的图像
private boolean isFirstPoint = true;
private BackgroundImage labFullScreenImage = new BackgroundImage();
private Robot robot;
private BufferedImage fullScreenImage;
private BufferedImage pickedImage;
private String defaultImageFormater = "png";
private JDialog dialog = new JDialog();
}
/**显示图片的Label*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawRect(x,y,w,h);
String area = Integer.toString(w)+" * "+ Integer.toString(h);
g.drawString(area,x+(int)w/2-15,y+(int)h/2);
g.drawLine(lineX,0,lineX,getHeight());
g.drawLine(0,lineY,getWidth(),lineY);
}
public void drawRectangle(int x,int y,int width,int height) {
this.x = x;
this.y = y;
h = height;
w = width;
repaint();
}
public void drawCross(int x,int y) {
lineX = x;
lineY = y;
repaint();
}
int lineX,lineY;
int x,y,h,w;
}
来源:赛迪网