2005年10月12日 星期三

[java] Convert Color Image To Gray Level Image


import java.awt.color.*;
import java.awt.image.*;
import java.imageio.*;
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp op = new ColorConvertOp(cs, null);
try {
BufferedImage colorImage =
ImageIO.read(new File("C:\\MATLAB701\\work\\1100608946.jpg"));
BufferedImage grayImage = op.filter(colorImage, null);
JFrame grayjf = new JFrame();
grayjf.getContentPane().add(new JButton(new ImageIcon(grayImage)));
grayjf.setSize(colorImage.getWidth(), colorImage.getHeight());
grayjf.setVisible(true);
}catch(Exception e) {
System.out.println("Error on reading color image");
}




沒有留言: