buffered image with transparency

This question is actually two parts.

Hello I am writing a simple game in which I move a little graphics character across the screen. The character is a car, and the background image that the car moves across is a picture of some mountains. How do I set a transparent color for the car windows, and the rectangular region that surrounds the graphics image of the car?. I have done this in C++ but not in Java. So in other words a certain color needs to be designated as the transparent color. I need to know how to set the tranparent color using Java methods/attributes. Not through an image editor.

Also, the image is currently a gif, but I also need to ask what the best choice for a graphics image on the web is?. Should I use .gif, .jpg, .pcx. I am looking for something really portable. One of my concerns is that I once heard that Compuserve tried to patent gifs.

Also, I am not using Swing.

Thanks in advance!!! Val

[953 byte] By [JavaIsGreata] at [2007-9-28 10:04:03]
# 1
Take a look at PNG for a portable, royalty-free image type that is available both in true color and palette 'modes.'
markuskidda at 2007-7-11 23:40:11 > top of Java-index,Other Topics,Java Game Development...
# 2
Well you answered some of the second questions, but really none of the first part of the question. Thank you for the help, but I hope you did not get those 10 points because my question was not answered.
JavaIsGreata at 2007-7-11 23:40:11 > top of Java-index,Other Topics,Java Game Development...
# 3

You're maybe just searching for the AlphaComposite Class.

You'd create a AlphaComposite through the static getInstance(int rule), getInstance(int rule, float alpha) methods

alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f);

then a call of getComposite() on your object should to the trick

refer to the api for info about rules available

hf,

dani

daniDGa at 2007-7-11 23:40:11 > top of Java-index,Other Topics,Java Game Development...
# 4
of course it issetComposite(alpha):D
daniDGa at 2007-7-11 23:40:11 > top of Java-index,Other Topics,Java Game Development...
# 5

class Transparency {

public static Image makeColorTransparent

(Image im, final Color color) {

ImageFilter filter = new RGBImageFilter() {

// the color we are looking for... Alpha bits are set to opaque

public int markerRGB = color.getRGB() | 0xFF000000;

public final int filterRGB(int x, int y, int rgb) {

if ( ( rgb | 0xFF000000 ) == markerRGB ) {

// Mark the alpha bits as zero - transparent

return 0x00FFFFFF & rgb;

}

else {

// nothing to do

return rgb;

}

}

};

ImageProducer ip = new FilteredImageSource(im.getSource(), filter);

return Toolkit.getDefaultToolkit().createImage(ip);

}

}

That should filter the image for you, also remember with class java.awt.image.BufferedImage, in order to use alpha-transparency you must create a BufferedImage of type ARGB or "Alpha-RGB" or something similar in order to read palette alpha entries.

Stviemra at 2007-7-11 23:40:11 > top of Java-index,Other Topics,Java Game Development...