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 & HelpPrograms › reading pixels
Page Index Toggle Pages: 1
reading pixels (Read 757 times)
reading pixels
Jun 25th, 2009, 5:55am
 
Hello,
I'm a relative newbie to Pimage and I can't quite get my head around the math of reading and displaying images. I'm trying to read each vertical line of an image (and display it as you'll see below.) It's supposed to be one of the Pimage exercises turned sideways to read columns instead of rows. Right now it's only reading the first column. How do I have it read each line and display it as it goes?

I am having on of those moments where I know when someone posts the answer I'm going to smack my head and say "stupid stupid me."

Thanks in advance.

Code:
PImage a;
boolean onetime = true;
int[] aPixels = new int[200*200];
int direction = 1;
float signal;

void setup()
{
 size(200, 200);
 stroke(255);
 a = loadImage("whatever.jpg");
 for(int i=0; i<width*height; i++) {
   aPixels[i] = a.pixels[i];
 }
}

void draw()
{
 if (signal > height-1 || signal < 0) {
   direction = direction * -1;
 }
 
 signal += (0.3*direction);  

 loadPixels();
 for (int i=0; i<width*height; i++) {
   pixels[i] = aPixels[int(signal)+int(i%height)];
 }

 updatePixels();
}
Re: reading pixels
Reply #1 - Jun 25th, 2009, 8:30am
 
It is unclear whether you want to display vertical or horizontal line, but changing it is quite trivial.
Here is my version:
Code:
PImage a;
boolean onetime = true;
int direction = 1;
float signal;

void setup()
{
 size(252, 252); // Just the size of my test image
 // Supposed to be of same size
 a = loadImage("E:/Dev/PhiLhoSoft/Processing/SqMe.png");
}

void draw()
{
 background(0); // Or not if you want the image
 // to appear wholly, but then changing direction makes no sense
 
 if (signal > width-1 || signal < 0) {
   direction *= -1;
 }
 
 signal += 0.3*direction;

 loadPixels();
 for (int i = 0; i < height; i++) {
   pixels[int(signal) + i * width] = a.pixels[int(signal) + i * width];
 }

 updatePixels();
}

No need to copy the pixels of the image.
Re: reading pixels
Reply #2 - Jun 25th, 2009, 8:57am
 
Phil, thank you very much. That was indeed a head slapper. I'm getting it slowly (I'm an audio person.)
Page Index Toggle Pages: 1