Java 彩色图转灰度图

1. 方法1
BufferedImage grayImage = new BufferedImage(width, height, colorImage.TYPE_BYTE_GRAY);  
Graphics g = grayImage.getGraphics();  
g.drawImage(colorImage, 0, 0, null);  
g.dispose();

 

2. 方法2(不推荐)

ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);  
ColorConvertOp op = new ColorConvertOp(cs, null);  
BufferedImage grayImage = op.filter(colorImage, null);

注意这种方法得到的灰度图grayImage与彩色图colorImage的通道数一样。


出处: http://stackoverflow.com/questions/9131678/convert-a-rgb-image-to-grayscale-image-reducing-the-memory-in-java



posted on 2017-01-12 20:14  兔子二  阅读(333)  评论(0编辑  收藏  举报

导航