topical media & game development
graphic-processing-algorithm-Ch05-p113-p113.pde / pde
PImage myImage; //define an image object
myImage = loadImage("memorial.jpg"); //load it
size(myImage.width,myImage.height); //size it to fit the window
image(myImage, 0,0); //display the image
for(int y=0; y<myImage.height; y++) //for all pixels in y
for(int x=0; x<myImage.width; x++){ //for all pixels in x
color myPixel = get(x,y); //get a pixel’s color
int a = int(alpha(myPixel)); //extract the alpha value
int r = int(red(myPixel)); //extract the red value
int g = int(green(myPixel)); //extract the green value
int b = int(blue(myPixel)); //extract the blue value
color inverse = color(255-a,255-r,255-g,255-b);
//make a color by inverting (255-value)
set(x,y,inverse); //set the pixel’s color in the image
}
save("memorial_inverted.jpg"); // save the image as a file
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.