This site requires JavaScript, please enable it in your browser!
Greenfoot back
Entity1037
Entity1037 wrote ...

2013/11/30

Change color of an Image ?

Entity1037 Entity1037

2013/11/30

#
I want to make a png image glow by changing color by only changing the color of the colored pixels in the image. How do I do something like this? (Example: make a png of a sphere glow yellowish and whitish but only on the sphere and not the entire square image).
danpost danpost

2013/11/30

#
There are at least two ways to accomplish this. One is to work with the image of the actor itself which would require you to hold the original image in an instance field and create a new image from each before changing it. The other is to create a new class to create an object to produce the 'glow' image to place over the image of the actor. I did something like the second way in my Pong Pinball scenario. The code is open source if you wish to see how I did it.
Entity1037 Entity1037

2013/11/30

#
I just used the sphere example to get my point across. I would like an image that could have it's pixels change color on the image itself. Let's say make Megaman X flash white and yellow while he's charging his buster, or an enemy get filled in with white but still maintain it's outline. I have no clue how to do something like that though. Do you know?
danpost danpost

2013/11/30

#
It might be best (although somewhat involved) to use an image editor to change your image(s) so that all colored pixels are white with non-colored pixels transparent and save the image(s) anew. If you do not have an image editor that supports transparency, you can make the exterior (non-colored) pixels BLACK and download and use my Image Transparency Adder scenario to change the BLACK area to transparent. Then you can use these new image to create to 'glow' by adjusting the transparency value of these new images over top of the image(s) of your actor.
Entity1037 Entity1037

2013/11/30

#
Geeze.... that's a LOT of images I have to make..... are you sure? Isn't there some method I could make to go recolor the pixels one by one? I mean seriously, it's bad enough I have to use elaborate sprite sheets for my images... Can't I just detect if a pixel is 100% transparent or not, and if it is, then change it's color so that it's a certain amount more yellow or white or something? I would just like to be able to do this with any image by using the same basic method (which I could put in my sprite sheet cutter class).
danpost danpost

2013/11/30

#
If you want to create a method to do that, create one. You would use a double 'for' loop (one for iterating across the image and one for iterating down the image), followed by using methods from the GreenfootImage class; like 'getColorAt' and 'setColorAt'. After getting the color, use the 'equals' method to compare each color against transparent (or compare the Alpha part of the color with zero).
You need to login to post a reply.