Greg Peters
Greg Peters

Reputation: 119

Changing the color of a BufferedImage

Hi all I am calculating a fractal and drawing a bufferedImage based on the number of completedIterations. For the sake of simplicity lets I am coloring the bufferdImage using the completedIterations in this way:

g.setColor(Color.getHSBColor((float) (colorValue - completedIterations), 1F, 1F));

Where colourValue is constant while the image is being generated, lets say in this case it's 0.2.

I have a slider on a JPanel, which when used, changes the colorValue, in the range of 0 to 1. When the colorValue is changed I want to update the BufferedImage in real time, but I don't want to recalculate all the image points as this causes a massive overhead - I just want to recolor the BufferedImage based on the new colorValue.

Can this be done, and if so how would I go about implementing it?

Kind regards

Greg

Upvotes: 3

Views: 2574

Answers (1)

trashgod
trashgod

Reputation: 205765

You can set individual pixels using setRGB(), as shown here; or adjust multiple pixels using RescaleOp, as shown here.

Upvotes: 2

Related Questions