tags:

views:

104

answers:

2

I have a set of icon images of various sizes (16x16, 24x24, 32x32) and base colours (red, green, blue, cyan, magenta, yellow). The images are pretty basic geometric patterns + drop shadow, so my gut feeling is that it should be pretty straightforward to replace the files with an icon factory that can generate images given a base colour.

However, subclassing the Image class seems to be a lot of work - is there a better way? Just to clarify - I'm not interested in generating image files, I intend to use the Image objects directly.

+2  A: 

What’s wrong with BufferedImage? It will give you a WritableRaster if you ask nicely. :)

Bombe
Of course! A BufferedImage, then createGraphics() and use the nice high-level drawing functions.
Christoffer
A: 

If you intend to paint the images to the screen, there is a better way. Write your class to extend the Icon interface, and use the paint method to actually use the Graphics2D APIs to draw the icon. You can pass the color to the constructor. I've done this before, and it works beautifully.

Ah, neat. I need the image both as an Image and as an Icon though, so I'll do the BufferedImage solution + an ImageIcon.
Christoffer