BufferedGraphicsContext.Allocate Method (Graphics, Rectangle)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a graphics buffer of the specified size using the pixel format of the specified Graphics.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public BufferedGraphics Allocate(
	Graphics targetGraphics,
	Rectangle targetRectangle


Type: System.Drawing.Graphics

The Graphics to match the pixel format for the new buffer to.

Type: System.Drawing.Rectangle

A Rectangle indicating the size of the buffer to create.

Return Value

Type: System.Drawing.BufferedGraphics

A BufferedGraphics that can be used to draw to a buffer of the specified dimensions.

When you call the Allocate method with a rectangle whose size exceeds the value of the MaximumBuffer property, a temporary BufferedGraphicsContext is created to allocate the buffer and provide a temporary context for the buffer. The new BufferedGraphicsContext is distinct from the BufferedGraphicsContext for the application domain and it is disposed automatically when the BufferedGraphics returned by the Allocate method is disposed.

The following code example demonstrates creating a graphics buffer using the Allocate method. This code is part of a larger example provided for the BufferedGraphics class.

// Allocates a graphics buffer using the pixel format 
// of the specified Graphics object.
grafx = appDomainBufferedGraphicsContext.Allocate(this.CreateGraphics(), 
     new Rectangle( 0, 0, 400, 400 ));

.NET Framework
Available since 2.0
Return to top