Reference for Processing version 1.2. 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
example pic
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 DXF and PDF renderers require the filename parameter.

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 0127), this means that text characters will be opaque blocks. This will be fixed in a future release (Bug 641).
Syntax
createGraphics(width, height, renderer)
createGraphics(width, height, renderer, filename)
Parameters
width int: width in pixels
height int: height in pixels
renderer Either P2D (not yet implemented), P3D, JAVA2D, PDF, DXF
filename String: the name of the file
Returns PImage or null
Usage Web & Application
Related PGraphics
Updated on June 14, 2010 12:05:29pm EDT

Creative Commons License