So, right to the subject, im working on my first game project (the first im going to finnish all the way), and i want to use some pictures that i have drwan i paint. When i load the picture, theres a white aquare around. I tried to remove this square with this code:
But as i want to set the alpha value to zero, making the white colors invisible, they just turn black???
All the code for the class looks like this:
Can anyone tell me what im doing wrong?
Note: some the code might look unnecessary, but that is just desperate trys to make it work. (by the way "Tag" and "taget" are danish for "roof" and "the roof" jsut to avoid confussion)
This CAN be done in Java and learning the way opens the door to lots of other neat transformations. The way I learned to edit images was from "Core Java II" by Horstmann, in the "Advanced AWT" chapter.
Since you want to edit the alpha values, construct the BufferedImage of the type TYPE_INT_ARGB. Then make a WritableRaster. With that you can inspect and set the individual pixels.
Then you can use raster.getPixel(i,j, pixel) and raster.setPixel(i,j,pixel) where pixel is an int, with
pixel = red, pixel=green, pixel=blue, and pixel=alpha (with values from 0-255).
You only need to alter the alpha, nothing is gained by setting the others to black as far as I can see. If the alpha is 0, it's invisible anyway.
Looking at some code of mine, where I read an image file, I am noticing that I am loading the data into a temporary array for use in the construction of an entirely new BufferedImage. So, there may be a way to work directly on the file you have loaded in, but I don't seem to have done exactly what you are trying.
Hope this helps! I am also working on finishing my first game. Good luck to us both!
Joined: Feb 04, 2009
Thanks for thge help, the transparancy now worls just the way it should
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com