Hi,
Here is what I want to do: I have a color BufferedImage, and I want to convert it to a grayscale one. The original image is stored as a PNG. I came up with the following code fragment (I use the Sixlegs PNG library to load PNG files, as it appears that ImageIO sometimes fails to load some of them):
BufferedImageOp operation = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
BufferedImage my_icon;
BufferedImage my_disabled_icon;
(...)
try
{
my_icon = new PngImage().read(new File("duke.png"));
my_disabled_icon = operation.filter(my_icon, null);
}
catch (IOException e)
{
(...)
}
my_icon indeed contains a valid Image - I verified this by blitting the content of my_icon on screen.
OTOH, my_disabled_icon triggers a NullPointerException with Java Mustang (build 94) at the operation.filter() line. A typical Exception trace starts with:
java.lang.NullPointerException
at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:238)
I am puzzled by this - did I forget anything, or is that a bug I inadvertantly jumped on ?
Also, maybe there’s another, better way to generate a grayscale image from a coloured one ?