Reference for Processing version 1.5. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### createGraphics()
Examples |
    PGraphics pg;

    void setup() {
      size(100, 100);
      pg = createGraphics(80, 80, P3D);
    }

    void draw() {
      pg.beginDraw();
      pg.background(102);
      pg.stroke(255);
      pg.line(40, 40, mouseX, mouseY);
      pg.endDraw();
      image(pg, 10, 10);
    }
Description | Creates and returns a new PGraphics object of the types P2D, P3D, and JAVA2D. Use this class if you need to draw into an off-screen graphics buffer. It's not possible to use createGraphics() with OPENGL, because it doesn't allow offscreen use. The PDF renderer requires the filename parameter. The DXF renderer should not be used with createGraphics(), it's only built for use with beginRaw() and endRaw(). It's important to call any drawing commands between beginDraw() and endDraw() statements. This is also true for any commands that affect drawing, such as smooth() or colorMode(). Unlike the main drawing surface which is completely opaque, surfaces created with createGraphics() can have transparency. This makes it possible to draw into a graphics and maintain the alpha channel. By using save() to write a PNG or TGA file, the transparency of the graphics object will be honored. Note that transparency levels are binary: pixels are either complete opaque or transparent. For the time being (as of release 1.2.1), this means that text characters will be opaque blocks. This will be fixed in a future release (Issue 80).
Syntax |
    createGraphics(width, height, renderer)
    createGraphics(width, height, renderer, filename)
Parameters |
width | int: width in pixels
height | int: height in pixels
renderer | Either P2D, P3D, JAVA2D, PDF
filename | String: the name of the file
Returns | PImage or null
Usage | Web & Application
Related | PGraphics

Updated on August 30, 2010 04:29:39pm EDT