问题描述
现在已经有了24位位图,但用户需要单色位图。小弟才疏学浅,希望各个高手大侠帮帮忙!
解决方案
解决方案二:
http://zhidao.baidu.com/question/86621478.html灰度变换下面的程序使用三种方法对一个彩色图像进行灰度变换,变换的效果都不一样。一般而言,灰度变换的算法是将象素的三个颜色分量使用R*0.3+G*0.59+B*0.11得到灰度值,然后将之赋值给红绿蓝,这样颜色取得的效果就是灰度的。另一种就是取红绿蓝三色中的最大值作为灰度值。java核心包也有一种算法,但是没有看源代码,不知道具体算法是什么样的,效果和上述不同。/*GrayFilter.java*//*@author:cherami*//*email:cherami@163.net*/importjava.awt.image.*;publicclassGrayFilterextendsRGBImageFilter{intmodelStyle;publicGrayFilter(){modelStyle=GrayModel.CS_MAX;canFilterIndexColorModel=true;}publicGrayFilter(intstyle){modelStyle=style;canFilterIndexColorModel=true;}publicvoidsetColorModel(ColorModelcm){if(modelStyle==GrayModelelseif(modelStyle==GrayModel}publicintfilterRGB(intx,inty,intpixel){returnpixel;}}/*GrayModel.java*//*@author:cherami*//*email:cherami@163.net*/importjava.awt.image.*;publicclassGrayModelextendsColorModel{publicstaticfinalintCS_MAX=0;publicstaticfinalintCS_FLOAT=1;ColorModelsourceModel;intmodelStyle;publicGrayModel(ColorModelsourceModel){super(sourceModel.getPixelSize());this.sourceModel=sourceModel;modelStyle=0;}publicGrayModel(ColorModelsourceModel,intstyle){super(sourceModel.getPixelSize());this.sourceModel=sourceModel;modelStyle=style;}publicvoidsetGrayStyle(intstyle){modelStyle=style;}protectedintgetGrayLevel(intpixel){if(modelStyle==CS_MAX){returnMath.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));}elseif(modelStyle==CS_FLOAT){return(int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);}else{return0;}}publicintgetAlpha(intpixel){returnsourceModel.getAlpha(pixel);}publicintgetRed(intpixel){returngetGrayLevel(pixel);}publicintgetGreen(intpixel){returngetGrayLevel(pixel);}publicintgetBlue(intpixel){returngetGrayLevel(pixel);}publicintgetRGB(intpixel){intgray=getGrayLevel(pixel);return(getAlpha(pixel)<<24)+(gray<<16)+(gray<<8)+gray;}}