Copying graphics
Sometimes, you may want to reuse a set of graphic elements multiple times, e.g. a “sprite”, or just a collection of paths. You can achieve this by using the DrawGraphics
method, which lets you draw the contents of a Graphics
object on another Graphics
object.
The first step is to create a Graphics
object to hold the image that will be copied; you can do this by invoking the parameterless Graphics
constructor. Then you can draw on this new object as normal. Finally, you invoke the DrawGraphics
method on the original Graphics
object that you obtained from the page, passing the new Graphics
as an argument, together with a Point
or two doubles
that determine where the origin of the copied Graphics
will be placed.
The following example shows how this method can be used.
The DrawGraphics
method also has another overload, which accepts an additional parameter; this is used to apply filters to the image, and is described in the next section.