Image image = new Image(Display.getCurrent(), bounds.width,
bounds.height);
// Paints the figure on it using SWT graphics
GC gc = new GC(image);
Graphics swtGraphics = new SWTGraphics(gc);
paintFigure(shape, backgroundColor, bounds, swtGraphics);
// Draws the image on the original graphics
graphics.drawImage(image, 0, 0);
// Disposes image (and GC btw) and SWT graphics
image.dispose();
swtGraphics.dispose();
}
}