截屏三步

截屏第三步是紧接第二步而来,框选区域画面之后需要确定,可以设为鼠标双击,则在鼠标双击事件中执行:

BufferedImage pickedImage = fullScreenImage.getSubimage(recX, recY, recW, recH);

 之后是将画面保存为文件,可以用javax.imageio.ImageIO:

/**
 * saved as a PNG picture
 * @param file a file to be written to
 * @throws IOException
 */
public void saveAsPNG(BufferedImage pickedImage, File file) {
    try {
        ImageIO.write(pickedImage, "png", file);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 

如有再之后一些个性化设置比如循环截图则注意需要将状态清零,因为是单例,之前包括一些primitive都是有值的

你可能感兴趣的:(截屏)