Java image colouring problem

Hi I am making a particle emitter and have come across a problem. I have my image for the particle which is a star that is transparent on the outsides and slowly turns to pure white in the middle. The problem is that when I try to colour my particle, the whole thing gets coloured fully because it is either white or transparent or inbetween, so my particles just look like squares. Is there a way to make it so when I set a colour on drawImage that it does not colour the transparent bits? so if i drew the particle red, it should be transparent on the edges and slowly increasing in redness until the middle which is full red. Sorry if this is confusing I explained it the best I could.
thanks,
Roland

How are you coloring your particle?

Some time ago I used a RGBImageFilter to do this…
It worked with transparancy…

Extend RGBImageFilter and override filterRGB:

Something like:


public class MyColorFilter extends RGBImageFilter
{
        private int filter = 0xffff0000;
        public MyColorFilter(int filter) {
        this.filter = filter;
        }
	@Override
	public int filterRGB(int x, int y, int rgb) {
		return ((rgb & filter));
	}
}

Red would be: 0xffff0000
Green: 0xff00ff00
Blue: 0xff0000ff

Then use your Class with an ImageProducer:
iiTest = ImageIcon


ImageProducer producer = iiTest.getImage().getSource();
producer = new FilteredImageSource(producer, new MyColorFilter(0xffff0000));
iiTest.setImage(createImage(producer));

[quote]How are you coloring your particle?
[/quote]
g.drawImage(image, x, y, sizeX, sizeY, colour, null);
colour = 0xffff0000 or something like that

thanks derhannes.
I will try that. Is this the only way?

I managed to figure out how to do this using BufferedImage which may help someone.
First make the MyColourFilter class (thanks derhannes) then:


BufferedImage image = null;
		try 
		{
			image = ImageIO.read(url);
		} 
		catch (IOException e) 
		{
		}

bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		bf.getGraphics().drawImage(image, 0, 0,width,height, null);
		ImageProducer producer = bf.getSource();
		producer = new FilteredImageSource(producer, new MyColourFilter(_iColour));
		
		int[] rgbs = new int[width*height];
		PixelGrabber pg = new PixelGrabber(producer,0,0,width,height,rgbs,0,width);
		try 
		{
			pg.grabPixels();
		} 
		catch (Exception e1) 
		{
		}
		bf.setRGB(0, 0, width, height, rgbs, 0, width);
		
		return bf;