Java Example Program / Sample Source Code
import java.awt.AWTException;
import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.color.CMMException;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class CMMExceptionExample {
public static void main(String[] a) throws HeadlessException, AWTException,
IOException {
try {
BufferedImage fSrcImage = new Robot()
.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
ColorSpace gray_space = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp convertToGrayOp = new ColorConvertOp(gray_space,
null);
BufferedImage fDstImage = convertToGrayOp.filter(fSrcImage, null);
File imageFile = new File("screenshot.png");
ImageIO.write(fDstImage, "png", imageFile);
} catch (CMMException e) {
throw new CMMException("Writing failed ");
}
}
} |
|
|