Support Forums

Full Version: Image transparency lulz
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
public void setAlpha(int alpha, int width, int height) {
        if (alpha < 0)
                alpha = 0;
        else if (alpha > 100)
                alpha = 100;

        alpha *= 2.55;

        int w = width;
        int h = height;

        int[] pixels = new int[w * h];

        pixels = this.image.getRGB(0, 0, w, h, pixels, 0, w);

        for(int i = 0; i < pixels.length; i++)
                pixels[i] = ((pixels[i] == 0) ? 0 << 24 : alpha << 24) | (pixels[i] & 0xffffff);

        this.image.setRGB(0, 0, w, h, pixels, 0, w);
    }

Enjoy, rofl.
I'm kind of new to this, so do I have to insert anything else? Because when I used the w3school's Java Tryit Editor, it didn't show anything transparent, in fact a lot of the code is all that displayed.
All you do is invoke it. Of course, its meant for pictures and such.