I created a module with 3.0.17 and everything looks and works great, but when I load it with the beta (4 or 5) all of the PNG images show their white backgrounds.
Hi, Brent. Sorry, I wish I could have linked it, but I was denied permission to publish the module publically. I can probably send it to you privately, though, in the interest of Vassal improvement…
There is a difference in the way 3.0 and 3.1 is handling the loading of some images. I have sent you one of the images by direct email.
Under 3.0, this image loads into a Basic Piece with a transparent background. Loading the same image in the same way into 3.1 and the transparent part of the image is white.
It is something about the format of the image. In Gimp, If I load this image, it looks normal with a transparent surround. If I select the transparent part, cut it out, then save the image, the image looks the same, but will now load into 3.1 correctly.
The image is indexed 8-bit, with one color specified as transparent. It
appears that the transparent color (which happens to be white) is not
being recognized as transparent.
I thought at first that this was a bug introduced by the work I did two
weeks ago on loading compatible images, but then I tried loading the image
in 3.1.0-beta3, and get at white background there, also—so this problem
has been around for some time.
I now think that either we’re not using ImageIO correctly, or this is an
ImageIO bug. Try loading this image with the following test program:
public class Test {
public static void main(String args) throws Exception {
final JFrame frame = new JFrame();
final JLabel label =
new JLabel(new ImageIcon(ImageIO.read(new File(args[0]))));
public class Test {
public static void main(String args) throws Exception {
final JFrame frame = new JFrame();
final JLabel label = new JLabel(new ImageIcon(
Toolkit.getDefaultToolkit().createImage(new URL(“file://” + args[0]))));
That’s obnoxious, as it looks like we have to start using the Toolkit
again for loading images unless we have a way of detecting these images
on the fly.
I think when you save the images with Gimp they end up as 32-bit ARGB,
which ImageIO has no problem loading. It’s probably the case that there
are very few 8-bit indexed transparent PNGs in use in modules, which
would explain why we hadn’t heard of this before.
They’re prefectly legal PNGs, so far as I can tell. ImageIO should be able
to load them successfully, so I think this is an ImageIO bug which I’ll
report to Sun.
We can work around this if I can figure out a way to detect when we have
an image of this type, and use Toolkit.createImage() for just those cases.
No, I use them all the time and have never had this problem.
In fact, the images are not indexed at all. I have just loaded up the one I sent you in Gimp and it tells me it is a full RGB image with no indexing. Merely saving the image from Gimp is enough to fix the problem.
I discovered something interesting just now: If I do nothing more than
open and save the image again in GIMP, whatever that changes is enough
for ImageIO.read() to do the right thing.
It turns out that I was wrong about GIMP saving the image out as 32-bit
ARGB. The image I saved was still indexed 8-bit.
If I compare the two images with ‘identify -verbose’, this is what’s
different between the original (<) and the one saved by GIMP (>):
My guess is that the change which made the difference is the Background
color entry. Possibly the PNG we’re dealing with here doesn’t actually
follow the standard?
No, Gimp only converts when writing PNG’s, not reading. If you load an indexed PNG image, you get put into Indexed mode, not RGB mode. Try loading back the image you saved in the previous step.
I’ve already looked at that. The original has no bKGD chunk, but it’s also
possible to get the GIMP to save one which lacks that too, and still loads
in ImageIO properly. So it’s not the lack bKGD chunk that’s the problem.
For the tRNS chunk, none of the working PNGs I save in the GIMP have one.
The original PNG has the following as its tRNS chunk:
00 FF 00 FF 00 FF 37 58 1B 7D 00 00 00 09
This looks odd to me, though I don’t see that it violates the specification.