FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   alphaArray...why isn't this working fully?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: alphaArray...why isn't this working fully?  (Read 471 times)
dabomb


alphaArray...why isn't this working fully?
« on: Nov 1st, 2004, 11:12pm »

Ok, so this code should work:
 
BImage a;
int[] alphaArray;
 
/*
 
void setup()  
{
  size(225, 300);
  a = loadImage("bush.jpg");
   
  int [] alphaArray = new int[225*300];
    for(int i=0; i < alphaArray.length; i++) {
    alphaArray[i] = 5;
  }
   a.alpha(alphaArray);
  }
 
void loop() {
  image (a, 0, 0);
}
*/
 
And it displays my lovely bush image, but gives me an error that says something like the alpha mask image must be the same size.  What?  What am I missing?
 
fjen

WWW
Re: alphaArray...why isn't this working fully?
« Reply #1 on: Nov 1st, 2004, 11:49pm »

change this line and try again:
 
from
int [] alphaArray = new int[225*300];
to  
int [] alphaArray = new int[ a.width * a.height ];
 
does this work?
alpha mask and the image you're applying it to must be same size.
 
/F
 
dabomb


Re: alphaArray...why isn't this working fully?
« Reply #2 on: Nov 2nd, 2004, 12:13am »

Hi there,
 
Thanks so much for replying to my question. There is an alpha mask happening, only my image is not there displaying.  I changed the int [] alphaArray = new int[225 * 300]   to int [] alphaArray = new int[a.width * a.height].  Did I miss an extra step
 
fjen

WWW
Re: alphaArray...why isn't this working fully?
« Reply #3 on: Nov 2nd, 2004, 12:23am »

have you tried using an other value, like 255 ?? because you are setting your image close to completely transparent (0) here:
 
for(int i=0; i < alphaArray.length; i++) {  
    alphaArray[i] = 5;  
  }  
 
 
try
 
for(int i=0; i < alphaArray.length; i++) {  
    alphaArray[i] = 255;  
  }  
 
black or 0 equals transparent,
white or 255 equals opaque
 
/F
 
dabomb


Re: alphaArray...why isn't this working fully?
« Reply #4 on: Nov 2nd, 2004, 1:38am »

Hey FJen,
 
One last question. Sorry to ask, again, but thanks for the help.  You stopped me from ripping out anymore of my hair.  Anyway so the code is as follows:  
 
 
BImage a;  
 int[] alphaArray;  
   
 
 void setup()  
 {  
   size(225, 300);  
   a = loadImage("bush.jpg");  
     
   int [] alphaArray = new int[a.width * a.height];  
     for(int i=0; i < alphaArray.length; i++) {  
     alphaArray[i] = 20;  
   }  
    a.alpha(alphaArray);  
   }  
   
 void loop() {  
   image (a, 0, 0);  
 }  
   
 
But, instead of fading OUT from Bush, in fades IN.  I want the image to appear first, then fade to black.  Right now, you see black then bush slowly appears.  It still looks really cool, just need to tweak. I moved some stuff around to setup and to loop, but it didn't change anything....
 
Best,
DaBomb
 
fjen

WWW
Re: alphaArray...why isn't this working fully?
« Reply #5 on: Nov 2nd, 2004, 5:27am »

ok. i see, try this:
Code:

BImage a;  
int[] alphaArray;
float fadeStep = 255.0 / 100.0; // 100 steps
float fadeVal = 255.0;
void setup()
{
  size(225, 300);
  a = loadImage("test.png");
 
  alphaArray = new int[a.width * a.height];
  for(int i=0; i < alphaArray.length; i++) {
    alphaArray[i] = 255;  // white -> opaque
  }
  a.alpha(alphaArray);
}
void loop()
{
  background(color(0,0,0));
  fadeVal -= fadeStep;
  if (fadeVal >= 0) {
    for(int i=0; i < alphaArray.length; i++) {
 alphaArray[i] = int(fadeVal);  
    }
    a.alpha(alphaArray);
  }
  image (a, 0, 0);
}

 
oh, btw .. you had "int[] alphaArray" declared twice. make sure to define it only once at the beginning ..
 
best
/F
 
toxi

WWW
Re: alphaArray...why isn't this working fully?
« Reply #6 on: Nov 2nd, 2004, 12:24pm »

dabomb, let me refer you to an older thread on this forum about the same problem. in order to create a continuous fade sequence, you'll need to clear the background and modify the alpha mask every frame.
 

http://toxi.co.uk/
Pages: 1 

« Previous topic | Next topic »