

Images can be added to the data folder automatically via: loadImage() looks for image files stored in your Processing sketch's "data" folder. loadImage() takes one argument, a String indicating a file name, and loads the that file into memory.


Second, a new instance of a PImage object is created via the loadImage() method. First, a variable of type PImage, named "img," is declared. Using an instance of a PImage object is no different than using a user-defined class. Draw the image to the screen at coordinate (0,0) Make a new instance of a PImage by loading an image file PImage img // Declare a variable of type PImage In this tutorial, we'll examine PImage, a class for loading and displaying an image as well as looking at its pixels. In addition to user-defined objects (such as Ball), Processing has a bunch of handy classes all ready to go without us writing any code. Though perhaps a bit trickier, you hopefully also use objects, complex data types that store multiple pieces of data (along with functionality)-a "Ball" class, for example, might include floating point variables for location, size, and speed as well as methods to move, display itself, and so on. These are all primitive data types, bits sitting in the computer's memory ready for our use. You probably specify them often-a float variable "speed", an int "x", etc. Hopefully, you are comfortable with the idea of data types. This tutorial is dedicated to breaking out of simple shape drawing in Processing and using images (and their pixels) as the building blocks of Processing graphics. With a little creative thinking and some lower level manipulation of pixels with code, however, we can display that information in a myriad of ways. Most of the time, we view these pixels as miniature rectangles sandwiched together on a computer screen. If you see any errors or have comments, please let us know.Ī digital image is nothing more than data-numbers indicating variations of red, green, and blue at a particular location on a grid of pixels. This tutorial is from the book Learning Processing by Daniel Shiffman, published by Morgan Kaufmann, © 2008 Elsevier Inc.
