I found that the best way is by using the JMyron library with a USB webcam. You will have to mess around with the dll's though because it uses native code... there's a working example somewhere if you google for it (I don't know exactly where) but I know that you need the dll's in your path. Download the Processing library and find the dll's and the jar.
import JMyron.JMyron;
//initializer
int width=100;//insert your numbers here
int height=100;
JMyron jmyron = new JMyron();
jmyron.start(width,height);
//in a loop
jmyron.update();
int[] image = jmyron.image();
image will be an int[] with length width*height. it stores the pixels row-by-row, so the first width
pixels will be the first row, the second width
pixels will be the second row, and so on.