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.

Example

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

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    Img: IGxBitmap;
    ImgFont: IGxFont;
    ImgBrush: IGxBrush;
    Graph: IGxGraphics;
    i: Integer;
Begin
    
//Create image
    Img := GxBitmap.CreateNew(ImageBox1.ClientWidth, ImageBox1.ClientHeight, GxPixelFormat.Format32bppArgb);
    ImgFont := 
New GxFont.Create("Times New Roman"16, GxFontStyle.BoldItalic, GxUnit.World);
    ImgBrush := 
New GxSolidBrush.Create(GxColor.FromName("Red"));
    Graph := GxGraphicsClass.FromImage(Img);
    
//Save the state
    i := Graph.SaveState;
    Graph.SetScale(
22);
    Graph.DrawTextW(
"First label", ImgFont, ImgBrush, 010);
    Graph.RestoreState(i);
    Graph.DrawTextW(
"Second label", ImgFont, ImgBrush, 00);
    ImageBox1.Image := Img;
End Sub Button1OnClick;

Clicking the button in the ImageBox component displays a new bitmap which state parameters will be saved to stack. Bitmap scale will be changed and a text message with defined settings will be displayed. After displaying the first message, the bitmap state parameters are restored and the second message is displayed.

See also:

IGxGraphics