tags:

views:

98

answers:

2

I have an image that I want to show some 'spotlights' on, like they do on TV. The rest of the image should be darker than the original, and the person that I'm spotlighting should be normal. I have the x,y and radius of the spotlight, but I'm not sure how to change the brightness at that location.

Also, if I have two spotlights and they intersect, the intersection should be brighter than either of the spotlights.

A: 

A simple way is to convert the color to HSL, lower L to darken, increase to lighten, then convert back to RGB and set the pixel.

http://www.mpa-garching.mpg.de/MPA-GRAPHICS/hsl-rgb.html

Lou Franco
Converting to HSL and back again is probably overkill for this - just multiply non-highlighted pixels by e.g. 0.8 for each of the R, G, B components.
Alnitak
+1  A: 

Use RescaleOp on the original image and subimages. Given that you have a buffered image (called biDest) that contains the image, call RescaleOp(0.6, 0, null) on it to make it darker. Then, to add a (rectangular) spotlight, call the following:

    public void spotLight(int x, int y, int w, int h)
    {
        BufferedImage i = biDest.getSubimage(x, y, w, h);

        RescaleOp rescale = new RescaleOp(SPOTLIGHT_BRIGHTNESS, 0, null);
        rescale.filter(i, i);

        repaint();
    }