3 2D Graphics and Animation

Sketch 27: Saving an Image and Adjusting Transparency

We are going to write a sketch that will allow the user to select a color in an image that will become transparent, and then save the image as a GIF. We can save any PImage in a file, just as most image files can be read into a PImage. If img is a PImage variable, we can save it as a file using this function call:

img.save ("image.jpg");

The parameter is the name of the file to be created. In the situation above, it will create a file named image.jpg and save the pixels of the PImage in JPEG format. The format is conveniently determined by the last three letters ...

Get An Artist's Guide to Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.