Manipulating the Alpha Raster

I’m bit confused on the proper method to manipulating the AlphaRaster directly on a TYPE_INT_ARGB BufferedImage. Setting the data values individually seems to have no effect.

I believe AlphaComposite can also be used for this purpose… but I don’t how to do that either.

If anyone could explain it, it would be greatly appreciated.

NOTE: Just noticed I accidentally put this in Game Play & Design… that was completely unintentional. If a mod wants to move it that’s fine.

There are two types of ARGB true colour.
One uses a “float” in the raster
the second type of ARGB use 0-255 inclusive to set the opacity.
By completeness that’s four(different values of the “static field constant” for BufferedImage type) types of true colour Alpha image.
“Pre” means one byte of alpha information is there for the whole/complete set of pixels.
so:
pre with “float(one??? 8 bit byte)” or “float[x][y] as an alpha raster”
pre with “int(one??? 8 bit byte)” or "int[x][y] as an alpha raster
*??? i’m not sure how the single value for the opacity(alpha value) setting is stored in the header or inside the runtime engine under the common image spec(doesn’t actually matter).

An alpha raster you can obtain from a buffered image.
AlphaComposite class is mostly for getting two images and combining the pixels(blending) by a set of rules as stated in the API docs.

AlphaComposite will do everything you want :wink:

From an not-so-old LD project (LD #23):


	public void render(Graphics2D g) {
		AlphaComposite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
		g.setComposite(c);

That’s how I used it, to create a “night”-Effect. I just rendered a Rectangle over the scene after drawing the scene itself:


		g.setColor(new Color(0f, 0f, 0f, 1f-brightness));
		g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

And thats almost everything, how to use it. Just keep sure, you draw everything in the right order :slight_smile: