Here you can find the source of capture(final String fileName, final Rectangle rect)
Parameter | Description |
---|---|
fileName | output file name. |
rect | rectangle size. |
public static void capture(final String fileName, final Rectangle rect)
//package com.java2s; //License from project: Open Source License 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 Main { /**// w ww .j a va 2 s. co m * capture current window. * @param fileName output file name. * @param rect rectangle size. */ public static void capture(final String fileName, final Rectangle rect) { final String name = fileName.toLowerCase().endsWith(".png") ? fileName : fileName.concat(".png"); try { final BufferedImage img = new Robot().createScreenCapture(rect); ImageIO.write(img, "png", new File(name)); } catch (final IOException | AWTException e) { e.printStackTrace(); } } }