Working with images
In the previous recipes, we've drawn vector-based shapes to the screen. Processing can also be used to manipulate images. In this recipe, we'll take a look at loading an image, displaying it on the screen, changing the color of a pixel, and copy/paste parts of an image.
Getting ready
Open one of your favorite pictures, resize and crop it with Photoshop so it's 640 x 480 pixels. If you don't have Photoshop, you can use GIMP, an open source image editor. GIMP is available for Linux, Windows, and Mac OS X. You can get it at http://www.gimp.org/.
How to do it...
Create a new sketch and save it as working_with_images.pde
. Once you have done this, you can drag the picture you've just resized onto the Processing editor. This is the easiest way to add files to your sketch. If you've completed these steps, you can start typing code. The first thing we'll do is declare some variables.
PImage img; // some settings to play with boolean pixelMode = false; int copyWidth = 50; int copyHeight...