Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Java image colouring problem  (Read 1037 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2009-11-02 09:26:33 »

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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2009-11-02 13:30:41 »

How are you coloring your particle?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline derhannes

Senior Newbie


Projects: 1



« Reply #2 - Posted 2009-11-02 22:42:00 »

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

Extend RGBImageFilter and override filterRGB:

Something like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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
1  
2  
3  
ImageProducer producer = iiTest.getImage().getSource();
producer = new FilteredImageSource(producer, new MyColorFilter(0xffff0000));
iiTest.setImage(createImage(producer));



Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #3 - Posted 2009-11-03 06:14:36 »

Quote
How are you coloring your particle?
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?
Offline roland
« Reply #4 - Posted 2009-11-07 10:40:48 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
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;
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!