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.ColorSpace;
import java.awt.color.ProfileDataException;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ProfileDataExceptionExample {
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 (ProfileDataException e) {
throw new ProfileDataException ("Writing failed ");
}
}
} |
|
|