Fiorenza Oppici wrote:
Brendan Jones wrote:
Fiorenza Oppici wrote:so, let me understand, your question is how to create a new color instance using both the old color info and the new alpha value, or it's more a problem regarding code for doing that? : )
My question is how would I go about getting the value of the new color. I have no problem actually setting the pixel color and then drawing the image to the screen, I just don't know how to implement transparency into the pixels.
as far as i know the int oldColor contains the info for red component in bits 16-23, for green component in bits 8-15 and for the blue ones in bits 0-7, as the Javadoc says.
so, you can get from that single int three other ints red, green, and blue truncating the bits and then shift divide each chunk with the right weight, so then you can instanciate the Color e.g "newcolor" with the constructor (int red, int g, int b, int alpha).
all this work can be done simply calling the Color methods getGreen(), getRed() e getBlue(). I'm not comfortable with shifting so I'd go for this option.
but you already used shifting and bitwise operations in your below code, so you can do the first way.
maybe someone can be more explicative on the exact code for converting the int into separate components, i found some examples on the web but I never suggest something it's not my own code... however, I hope i've been hepful.
blue = bits 0 - 7
green = bits 8-15
red = bits 16-23
alpha = bits 24-31
I know how the color data is stored, so my issue isn't getting the RGBA values of the colors (That's quite simple).
Say, for example, I had a black background and wrote 'Transparency' in white letters on it. Now, if I were to draw a transparent red rectangle over it, you would be able to see the letters through the red. While if it were fully opaque, the red would cover everything (Black & White) up and you would see nothing but a red rectangle.
What I need to know is how I'd calculate what color I should actually paint the pixel. If I were to set the color to a transparent value, it would just be that color (It won't 'blend' with the colors below it, it would just overwrite them).
-----------------------------------
Edit: Nevermind, after an hour or so of searching on Google, I managed to find a formula for calculating colors. For anyone that was wondering, it looks like this.
Note: All of the float values must be between the value of 0.0 and 1.0.
Hope this helps someone