IGxGraphics.SaveState

Syntax

SaveState: Integer;

Description

The SaveState method saves the state of the graphic object to the stack.

Comments

The SaveState method can be called for several times before the RestoreState method is called, a new index of the graphic object state is returned. When passing one of the state indexes to the RestoreState method the graphic object is restored in accordance with the saved settings. State parameters with this index are deleted from the stack as well as the states that are put into the stack after calling the SaveState method with this index.

Fore Example

Executing the example requires a form with the button named Button1 and the ImageBox component named ImageBox1. Add links to the Drawing, Forms system assemblies.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    BMP: IGxBitmap;
    GraphClass: GxGraphicsClass;
    Graph: IGxGraphics;
    Font: IGxFont;
    Brush: IGxBrush;
    i: Integer;
Begin
    
//Create a raster image according to the size of the ImageBox1 component
    BMP := GxBitmap.CreateNew(ImageBox1.ClientWidth, ImageBox1.ClientHeight, GxPixelFormat.Unknown);
    Font := 
New GxFont.Create("Times New Roman"16, GxFontStyle.BoldItalic, GxUnit.World);
    Brush := 
New GxSolidBrush.Create(GxColor.FromName("Red"));
    GraphClass := 
New GxGraphicsClass.Create;
    Graph := GraphClass.FromImage(BMP);
    
//Save the state
    i := Graph.SaveState;
    Graph.SetScale(
55);
    Graph.DrawTextW(
"First title", Font, Brush, 00);
    Graph.RestoreState(i);
    Graph.DrawTextW(
"Second title", Font, Brush, 00);
    ImageBox1.Image := BMP;
End Sub Button1OnClick;

After executing the example clicking the button in the ImageBox component displays a new bitmap, which state parameters are stored in the stack. The image zoom is changed and text message according to the settings is displayed. After displaying of the first message the bitmap state parameters are restored, and the second message is displayed.

See also:

IGxGraphics