We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Easiest way to add alpha value to colour
Page Index Toggle Pages: 1
Easiest way to add alpha value to colour? (Read 576 times)
Easiest way to add alpha value to colour?
Oct 3rd, 2007, 10:44pm
 
Hello!

What is the simplest and fastest way to add an alpha value to a RGB colour?

At the moment I'm extracting the red, green and blue values from the old colour and put them together again with an alpha value. I'd like to simply add an alpha to the whole rgb colour value, but don't know how. =/

Thanks for your help.
Re: Easiest way to add alpha value to colour?
Reply #1 - Oct 3rd, 2007, 10:53pm
 
Hi,

I'm not quite sure I understand your request but from what I understand can't you just add the alpha in the fill statement

For example : fill(r,g,b,alpha)

If this is not what you're looking for, could you please give more explanation.

Thanks
Re: Easiest way to add alpha value to colour?
Reply #2 - Oct 3rd, 2007, 11:14pm
 
I'm reading rgb colour values from the pixels[] array. Now I want to add alpha to those values, without pulling apart the rgb values if possible.

At the moment I'm doing something like this (adding alpha of 100 to some colour):

Code:
newColour = 100 << 24 | (oldColour >> 16 & 0xFF) << 16 | (oldColour >> 8 & 0xFF) << 8 | oldColour & 0xFF; 



I'd like to skip the part of getting the single red, green and blue values from a colour and rather do something simple like rgb + alpha = new colour. But I don't know how.

Re: Easiest way to add alpha value to colour?
Reply #3 - Oct 3rd, 2007, 11:27pm
 
newcolor=(oldcolor&0x00FFFFFF)+0x60000000;
or if you don't know the hex value for the alpha, you can do:
newcolor=(oldcolor&0x00FFFFFF)+(100<<24);
Re: Easiest way to add alpha value to colour?
Reply #4 - Oct 3rd, 2007, 11:39pm
 
Yes, that's much better! ^^

Thanks for your replies JohnG and steven.
Page Index Toggle Pages: 1