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 › changing alpha value of a pixel with pixel array
Page Index Toggle Pages: 1
changing alpha value of a pixel with pixel array (Read 304 times)
changing alpha value of a pixel with pixel array
Mar 1st, 2009, 12:47pm
 
hello, im trying to change the colors and alpha value of  pixels of an image, first it analyzes a pic and based on a luminosity threshold it changes the colors and alpha value of the pixel, im using color with 4 values for changing the alpha value the 3 first ones are supposed to be the colors and the last one the alpha, but it doesnt work, Is there a special way to do this?
img.pixels[y] = color(0, 70, 0, 250);



here is the complete code:


int x;

PImage img;
PImage imgdos;
PImage imgtres;

color luminosidad;
float luminosidad_total;

color [] imagenn ;

float sube = 1;

void setup () {
 noStroke() ;
 strokeWeight(2) ;
 size (400, 400) ;
 img = loadImage("glitch.jpg");
 imgdos = loadImage("glitch.jpg");    
 imgtres = loadImage("glitch.jpg");
 
 loadPixels();
       
  for (int y = 0; y<img.height * img.width ;y++){
 luminosidad =  img.pixels[y];
 luminosidad_total =( ((red(luminosidad)) + (green(luminosidad)) + (blue(luminosidad)))/3);
       if(luminosidad_total<214){
             img.pixels[y] = color(0, 70, 0, 250);
       }
   
    if(luminosidad_total>124){
         imgdos.pixels[y] = color(80, 30, 0, 0);
        }
       
      if(luminosidad_total<184){
            imgtres.pixels[y] = color(0, 0, 0, 0);
           }
           }
updatePixels();

}
void draw()
{
 background(233) ;
 
x = x+ 1;
   image(img, 20, 10);
image(imgdos, x, 90);  
image(imgtres, 80, 180);
}
 
Re: changing alpha value of a pixel with pixel arr
Reply #1 - Mar 2nd, 2009, 6:04pm
 
Hi mateooo

To get to the imgdos pixels you need to go imgdos.loadPixels();
After you have manipulated them you need to call imgdos.updatePixels().

Calling loadPixels() (without anything in front of it) will load the pixels from what is currently on your screen and the same does updatePixels().

So I think you are doing every thing correctly, just need to update the imgdos, imgtres and img objects before you draw them again in your draw() method:

Also note that with the color() method and decimal numbers the alpha is the last value: color(R, G, B, A) but in hex notation it is the first color(0xAARRGGBB)

Hope it helps.
Page Index Toggle Pages: 1