keep transparency of png image with type TYPE_BYTE_INDEXED

Hi, i have a problem with a few png images. they have the type TYPE_BYTE_INDEXED. if i do any resizing or anything else with Graphics2D the transparency is lost..

here is a simple example..

BufferedImage bi = ImageIO.read(new File(args[0]));

double w = 450;

double oriw = bi.getHeight();

double orih = bi.getWidth();

double h = (oriw/orih)*450;

Image image = bi.getScaledInstance(450, (int)h , bi.getType());

BufferedImage biRes =new BufferedImage((int)w,(int)h,bi.getType());

Graphics2D bufImageGraphics = biRes.createGraphics();

bufImageGraphics.drawImage(image, 0, 0,null);

System.out.println(biRes.getType());

ImageIO.write(biRes,"png",new File(args[2]));

my actual java program is more complex like this..

is there anyway to "rescue" the transparency?

p.s. sorry for my bad english ;)

[1280 byte] By [mephia] at [2007-11-27 6:04:20]
# 1
not anybody an idea? is it maybe a bug in java?
mephia at 2007-7-12 16:48:18 > top of Java-index,Security,Cryptography...
# 2
hello?why does nobody have a solution for my problem?
mephia at 2007-7-12 16:48:18 > top of Java-index,Security,Cryptography...
# 3

Try something like this:

BufferedImage biRes = new BufferedImage(bi.getColorModel(), bi.getColorModel().createCompatibleWritableRaster(w, h), bi.isAlphaPremultiplied() , null);

You have to copy the color table to the new image.

The transparency data is written there.

Rodney_McKaya at 2007-7-12 16:48:18 > top of Java-index,Security,Cryptography...