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
   Programs
(Moderators: fry, REAS)
   setting alpha of an image
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: setting alpha of an image  (Read 430 times)
ufux


setting alpha of an image
« on: Feb 6th, 2005, 12:05pm »

I'm changing the alpha values of an image but it gets transparent for one frame then not for the next.  
 
Here is the code:
 
 
int wSize = 640;
int hSize = 480;
int bgColor = 0;
int tolerance =38;
int replacementColor = 0;
int[] imageAlpha;
BImage icon,bg;
 
void setup() {
  framerate(1);
  size(wSize,hSize);
  bg = loadImage("bg.gif");
  replacementColor = color(125,0,0,0);
  imageAlpha = new int[640*480];
  background(bg);
}
 
void loop() {
  //image(bg,0,0);
  bgColor = get(100,100);
  icon = loadImage("5.jpg");
  image(bg,0,0);
  for(int i=0;i<icon.width*icon.height;i++) {
    if(inColor(icon.pixels[i])) {
 imageAlpha[i] = 0;
    } else {
 imageAlpha[i] = 255;
    }
  }
  icon.alpha(imageAlpha);
   
  image(icon,0,0);
  System.out.println(icon.pixels[100*100]);
}
 
boolean inColor(int tcolor) {
  if(red(tcolor) < red(bgColor)+tolerance && red(tcolor) > red(bgColor)-tolerance) {
    if(green(tcolor) < green(bgColor)+tolerance && green(tcolor) > green(bgColor)-tolerance) {
 if(blue(tcolor) < blue(bgColor)+tolerance && blue(tcolor) > blue(bgColor)-tolerance) {
   return true;
 }
    }
  }
  return false;
}
 
 
fjen

WWW
Re: setting alpha of an image
« Reply #1 on: Feb 6th, 2005, 3:09pm »

it is a bad idea to use loadImage inside the loop. that's because disk access is always slow ...
 
maybe that already removes the behavior.
 
/F
 
Pages: 1 

« Previous topic | Next topic »