Java Buffered Image RescaleOp transparency issue

I seem to have a problem when I create a BufferedImage that has transparent pixels such as:

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

      

and it works fine until I filter it through RescaleOp to darken it. When I do this, the image disappears. Here is my complete code so you can see how I set it 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 can I fix this so that the buffered image will be darkened without affecting transparency?

+3


source to share


1 answer


You can try the RescaleOp

one that handles the alpha illustrated here and use the same lightLevel

for all color components.



+2


source







All Articles