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.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GetInstance_ColorSpace {
public static void main(String[] a) throws HeadlessException, AWTException, IOException{
BufferedImage fSrcImage = new Robot()
.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit()
.getScreenSize()));
ColorSpace gray_space = ColorSpace.getInstance(ColorSpace.CS_GRAY);
gray_space.fromCIEXYZ(new float[]{4.3f,3.1f,2.2f});
gray_space.fromRGB(new float[]{4.3f,3.1f,2.2f});
ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);
gray_space.getMaxValue(0);
gray_space.getMinValue(0);
gray_space.getName(0);
gray_space.getNumComponents();
gray_space.getType();
gray_space.isCS_sRGB();
gray_space.toCIEXYZ(new float[]{4.3f,3.1f,2.2f});
gray_space.toRGB(new float[]{4.3f,3.1f,2.2f});
ColorConvertOp convertToGrayOp = new ColorConvertOp(gray_space, null);
BufferedImage fDstImage = convertToGrayOp.filter(fSrcImage, null);
File imageFile = new File("screenshot.png");
ImageIO.write(fDstImage, "png", imageFile);
}
} |
|
|