Search code examples
javabufferedimagealpha

How to add an AlphaChannel to an existing png


I've been sitting and thinking about this probably the whole evening now.

How do you add an alpha channel to an image that does not have one.

My scenario: I have an image, which I import as a BufferedImage and do some stuff with it. Now I want to set it to be partially transparent but that does not work without an alpha channel. Sadly not all my images have one so I want the possibility to add one afterward. Is this possible? If yes: how?


Solution

  • The solution that worked for me: I created a new BufferedImage with an alpha channel and the same width and height as the one without and copied the pixels from the old one to the new one.