BufferedGraphicsContext::Allocate Method (IntPtr, 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:
[SecurityPermissionAttribute(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::UnmanagedCode)]
BufferedGraphics^ Allocate(
	IntPtr targetDC,
	Rectangle targetRectangle
)

Parameters

targetDC
Type: System::IntPtr

An IntPtr to a device context to match the pixel format of 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 handle to a device context.
grafx = appDomainBufferedGraphicsContext->Allocate( this->Handle,
   Rectangle( 0, 0, 400, 400 ) );

SecurityPermission

for access to unmanaged code. Related enumeration: UnmanagedCode

.NET Framework
Available since 2.0
Return to top
Show: