Results 1 to 5 of 5
  1. #1
    Cassidy is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Coloring an image

    I have created a game which is running fine. In it, I draw fancy-looking lines that are white in the middle and fade to transparent on the outside, AKA all color values are (255,255,255,someAlpha); I do this by simply loading a bitmap that I already rendered in Python. What I want to do is render it in a different color every frame, such as doing (255,255,0,sameAlpha) then (254,255,1,sameAlpha) (cycling hue). Is there any efficient way to do this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Can you show a picture of what you mean?

    Also, have you looked at the ColorConvertOp class? Perhaps it has what you need, since if you use it with an appropriate ColorSpace object, you can convert colors in most any way that you desire.
    Last edited by Fubarable; 05-31-2010 at 08:22 PM.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    What I want to do is render it in a different color every frame, such as doing (255,255,0,sameAlpha) then (254,255,1,sameAlpha) (cycling hue).
    You can use HSL Color to easily change the Hue of a Color. If you want to cycle I guess the most efficient way would be to create an Array of all 360 hues up front.

  4. #4
    Cassidy is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default


    Various Color classes can help in determining what color to use, but the biggest problem I'm facing is determining how to draw it to the screen. Once I have a white-and-alpha or black-and-white image and a color, how do I get it drawn to the screen the right way?
    Ideally there would exist some drawBlackAndWhiteImage function that allows one to specify a color.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Java Code:
    Graphics.setColor(...);
    Graphics.drawOval(...);
    Graphics.fillOval(...);
    You would use various combinations of the Graphics methods to get the painting effects you desire.

    Or if you want to change an image pixel by pixel you would create a BufferedImage, manipulate its pixels and then draw the image to the panel.

    There are probably other better techniques, but that all I know.

Similar Threads

  1. Coloring JTable cells
    By ProgrammingPup in forum Advanced Java
    Replies: 2
    Last Post: 11-04-2009, 10:57 PM
  2. Coloring an image
    By Twitchy5 in forum AWT / Swing
    Replies: 19
    Last Post: 09-12-2009, 03:44 PM
  3. Replies: 14
    Last Post: 04-10-2009, 08:46 AM
  4. Replies: 0
    Last Post: 07-25-2008, 02:31 PM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •