04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 10-23. Load an Image sketch<br />

Pretty painless, don’t you think? If you did run into a problem, remember that <strong>Processing</strong><br />

is case sensitive, so .JPG is different than .jpg. In addition, <strong>Processing</strong> can’t (easily) h<strong>and</strong>le<br />

huge files the way a program like Photoshop can, which can utilize virtual memory (memory<br />

borrowed from the hard drive). Also remember that image size <strong>and</strong> resolution are<br />

interconnected, so just changing the size of the image’s dimensions won’t reduce its memory<br />

requirements; it will just increase the resolution of the smaller image.<br />

If you’re working with a very large image <strong>and</strong> run into the java.lang.OutOfMemoryError,<br />

you can try allocating more memory to <strong>Processing</strong> by selecting Preferences from the top<br />

<strong>Processing</strong> menu. Make sure that the Set Maximum Available Memory box is selected, <strong>and</strong><br />

then try incrementally (<strong>and</strong> cautiously) raising the value. <strong>Processing</strong>’s default value is<br />

512KB. To learn more about memory issues/errors in <strong>Processing</strong>, check out http://<br />

processing.org/faq/bugs.html#memory.<br />

Notice in the last example that I declared the variable img1 of type PImage. Similarly to<br />

<strong>Processing</strong>’s color data type, PImage is a unique <strong>Processing</strong> data type, used to store image<br />

data. The line img1 = loadImage("heidi.jpg"); in the example creates a PImage object.<br />

This line didn’t actually draw the image to the screen, but constructed a PImage object<br />

containing the relevant image data.<br />

One of the challenges of loading images or other forms of external data is the latency, or<br />

delay, between the input request <strong>and</strong> the data actually being loaded into the program. As<br />

you can imagine, this delay can be substantial for large image files. Using pure Java, loading<br />

images can be a bit involved, requiring structures for tracking the image data as it’s<br />

loading—much lower-level than most of us would want to go. PImage, along with the<br />

loadImage() function, encapsulates this entire loading process (thankfully).<br />

COLOR AND IMAGING<br />

433<br />

10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!