彩色图像转灰度图像

代码
Image im;
BufferedImage bi;
//im初始化,int w,h;
bi=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
Graphics2D big
=bi.createGraphics();
big.drawImage(im,
0,0,this);

public void color2gray(){
ColorSpace cs
=ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp colorConvert
=new ColorConvertOp(cs,null);
colorConvert.filter(bi, bi);
}
//可以repaint了,只是在缓存区里面,并不是真正修改了文件
原文地址:https://www.cnblogs.com/frostbelt/p/1766359.html