ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); ColorConvertOp op = new ColorConvertOp(cs, null); BufferedImage grayImage = op.filter(colorImage, null);The way to convert an RGB value to grayscale is to use the following formula: brightness = 0.212671 * R + 0.715160 * G + 0.072169 * B. Assign brightness to the Red, Green, and Blue components of the a new RGB value.以上引自jGuru,希望能对你有所帮助
ColorSpace(int type, int numcomponents) Constructs a ColorSpace object given a color space type and the number of components 构造函数中的第一个参数就可以取ColorSpace中的static int 哦 也就是说你可以把type换成你说的TYPE_GRAY试试 那些TYPE_XXX都可以用来做第一个参数哦。从来没用过这个类,刚才翻文档才知道的
都是Java 2D的东西:) TYPE_XXX 不可以ColorSpace.getInstance(ColorSpace.TYPE_XXX); 也不可以 ColorSpace(int type, int numcomponents) 只有CS_XXX才能实例化 我想这也是他们用不同的前缀的原因。 用TYPE_XXX 会得到一个java.lang.IllegalArgumentException: Unknown color space
ColorConvertOp op = new ColorConvertOp(cs, null);
BufferedImage grayImage = op.filter(colorImage, null);The way to convert an RGB value to grayscale is to use the following formula: brightness = 0.212671 * R + 0.715160 * G + 0.072169 * B. Assign brightness to the Red, Green, and Blue components of the a new RGB value.以上引自jGuru,希望能对你有所帮助
Constructs a ColorSpace object given a color space type and the number of components
构造函数中的第一个参数就可以取ColorSpace中的static int 哦
也就是说你可以把type换成你说的TYPE_GRAY试试
那些TYPE_XXX都可以用来做第一个参数哦。从来没用过这个类,刚才翻文档才知道的
TYPE_XXX 不可以ColorSpace.getInstance(ColorSpace.TYPE_XXX);
也不可以 ColorSpace(int type, int numcomponents)
只有CS_XXX才能实例化
我想这也是他们用不同的前缀的原因。
用TYPE_XXX 会得到一个java.lang.IllegalArgumentException: Unknown color space
那样只能得到8bit grayscale
thx
and,有没有什么Java 2D的书?除了SUN上下载的。
我知道O'reilly出版过一本,不过找不到。