I am attempting to get the color of each pixel in an image. Using the get() function with coordinates yield garbage values or strange results (only a single color from the image rather than the color at a particular x,y point).
The image shows up fine. If I use the pixels array I can get the colors correctlu, but not the get() function.
PImage img;
size(400, 300); //4:3
img = loadImage("myjpg.jpg");
image(img, 0,0, width, height);
// draw a square every 5 pixels with the fill color the same as a pixel at that point
for(int i=0; i < width*height; i+=5){
int x = i%width;
int y = floor(i/width)*5;
color c = get(x, y); // <--- have tried both img.get(x,y) and get(x,y) based on reference.
fill(red(c), green(c), blue(c), 255); //same results as fill(c)
rect(x, y, 20, 20);
}
Is this a bug or am I doing something incorrectly?