3

I seem to be having an issue where I create a BufferedImage which has transparent pixels like this:

BufferedImage buff = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);

and it works fine until I filter it through the RescaleOp to darken it. When I do this, the image disappears. Here is my complete code just so you can see how I am setting this up:

    BufferedImage buff = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = buff.createGraphics();
    g.drawImage(i, 0, 0, null);
    g.dispose();
    RescaleOp filter = new RescaleOp(lightlevel, 0f, null);
    buff = filter.filter(buff, null);

My question is, how do I fix this so the buffered image will have its pixels darkened without affecting the transparency?

MrDrProfessorTyler
  • 383
  • 2
  • 9
  • 26

1 Answers1

2

You could try the RescaleOp that handles alpha, illustrated here, and use the same lightLevel for all color components.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974
  • Don't I have the same exact thing there except without the offsets? – MrDrProfessorTyler Mar 08 '12 at 15:40
  • You're welcome; when you're satisfied, you can accept this answer by clicking on the [empty check mark](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) at the left. – trashgod Mar 08 '12 at 19:38