0

I am drawing a Bufferedimage

BufferedImage map = ImageIO.read(getClass().getResource("map.png"));

but I would like to either a) put a whiter filter on top, or b) change the alpha value so that it's not as bright. I've tried

for (int x = 0; x < map.getWidth(); x++) {
        for (int y = 0; y < map.getHeight(); y++)
        {
            int tempcolor = map.getRGB(x, y);
            int newalpha = (60 << 24) | (tempcolor & 0x00ffffff);
            map.setRGB(x, y, newalpha);
        }
        }
g.drawImage(map, 0, 0, this);

but the image looks exactly like the original. Any ideas?

Martin
  • 277
  • 2
  • 5
  • 17
  • 1
    Alpha will only allow the lower layer to show through. If there's no lower layer, nothing happens. – Marko Topolnik Jan 14 '14 at 12:57
  • That makes sense. So I can add a white layer behind it and that should fix the problem. – Martin Jan 14 '14 at 12:59
  • While probably slower than using `RescaleOp` your original code should work, given you have an image type (`BufferedImage.TYPE_xxx`) that supports alpha, like `BufferedImage.TYPE_INT_ARGB`. – Harald K Jan 14 '14 at 14:13

1 Answers1

4

you can use RescaleOp because that handles alpha,

    RescaleOp rescale = new RescaleOp(1.2f, 15, null);
    rescaleOp.filter(image, image); // Source and destination are the same.

refer this link also may help you more

one more link here for Brightness control

Community
  • 1
  • 1
Ashish
  • 1,943
  • 2
  • 14
  • 17