Method function IGDIPlus.IGPGraphics.BeginContainer(TGPRect;TGPRect;TGPUnit) : TGPGraphicsContainer

From Mitov Wiki Doc
Jump to: navigation, search

This is a Beta Read Only version of this page. Please review and send recommendations to mitov@mitov.com. We will enable the editing as soon as we are happy with the overall Wiki site.

Class: IGPGraphics

Contents

Syntax

Delphi:

function BeginContainer( dstrect : TGPRect, srcrect : TGPRect, unit_ : TGPUnit ) : TGPGraphicsContainer;

C++ Builder:

TGPGraphicsContainer __fastcall BeginContainer( TGPRect dstrect, TGPRect srcrect, TGPUnit unit_ );

Visual C++ (MFC):

BeginContainer(  dstrect,  srcrect,  unit_ );

Summary

Begins a new graphics container.

Description

Call this method to begin a new graphics container.


Example:

The following example calls the BeginContainer method to
create a graphics container. The code specifies a
transformation for the container by passing two rectangles to
the BeginContainer method. The code calls
Graphics::FillEllipse twice: once inside the container and
once outside the container (after the call to EndContainer).

var
  AGraphics : IGPGraphics;
  APath : GraphicsPath ;
  ABlackPen : IGPPen;
  AContainer : IGPGraphicsContainer;
  srcRect : TGPRect;
  destRect : TGPRect;

begin
  AGraphics := TGPGraphics.Create( ACanvas );

  // Define a translation and scale transformation for the container.


  srcRect := MakeRect(0, 0, 200, 100);
  destRect := MakeRect(100, 100, 200, 200);

  // Create a graphics container with a (100, 100) translation
  // and (1, 2) scale.
  AContainer := graphics.BeginContainer(destRect, srcRect, UnitPixel);

  // Fill an ellipse in the container.
  graphics.FillEllipse( TGPSolidBrush( aclRed ), 0, 0, 100, 60 );

  // End the container.
  graphics.EndContainer(AContainer);

  // Fill the same ellipse outside the container.
  graphics.FillEllipse( TGPSolidBrush( aclBlue ), 0, 0, 100, 60 );
end;

Remarks Use this method to create nested graphics containers. Graphics containers are used to retain graphics state, such as transformations, clipping regions, and various rendering properties.


The BeginContainer method returns a value of type GraphicsContainer. When you have finished using a container, pass that value to the EndContainer method. The GraphicsContainer data type is defined in Gdiplusenums.h.


The dstrect and srcrect parameters specify a transformation. It is the transformation that, when applied to srcrect, results in dstrect.


When you call the BeginContainer method of a Graphics object, an information block that holds the state of the Graphics object is put on a stack. The BeginContainer method returns a value that identifies that information block. When you pass the identifying value to the EndContainer method, the information block is removed from the stack and is used to restore the Graphics object to the state it was in at the time of the BeginContainer call.


Containers can be nested; that is, you can call the BeginContainer method several times before you call the EndContainer method. Each time you call the BeginContainer method, an information block is put on the stack, and you receive an identifier for the information block. When you pass one of those identifiers to the EndContainer method, the Graphics object is returned to the state it was in at the time of the BeginContainer call that returned that particular identifier. The information block placed on the stack by that BeginContainer call is removed from the stack, and all information blocks placed on that stack after that BeginContainer call are also removed.


Calls to the Save method place information blocks on the same stack as calls to the BeginContainer method. Just as an EndContainer call is paired with a BeginContainer call, a Restore call is paired with a Save call.



Caution When you call EndContainer, all information blocks placed on the stack (by Save or by BeginContainer) after the corresponding call to BeginContainer are removed from the stack. Likewise, when you call Restore, all information blocks placed on the stack (by Save or by BeginContainer) after the corresponding call to Save are removed from the stack.


For more information about graphics containers, see "Nested Graphics Containers" on MSDN.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox