Export (0) Print
Expand All

BufferedGraphicsContext.Allocate Method (Graphics, Rectangle)

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
)

Parameters

targetGraphics
Type: System.Drawing.Graphics

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

targetRectangle
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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft