Graphics.Save 메서드

정의

Graphics의 현재 상태를 저장하고 GraphicsState로 저장된 상태를 확인합니다.

public:
 System::Drawing::Drawing2D::GraphicsState ^ Save();
public System.Drawing.Drawing2D.GraphicsState Save ();
member this.Save : unit -> System.Drawing.Drawing2D.GraphicsState
Public Function Save () As GraphicsState

반환

이 메서드는 이 GraphicsState의 저장된 상태를 나타내는 Graphics를 반환합니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse 코드는 다음 작업을 수행합니다.

  • 벡터(100, 0)로 Windows Form의 월드 변환을 변환합니다.

  • 폼의 그래픽 상태를 저장합니다.

  • 폼의 월드 변환을 ID(2x2 ID 행렬 및 0벡터 변환)로 다시 설정하고 사각형을 단색 빨간색 브러시로 채웁니다.

  • 변환된 그래픽 상태를 복원하고 사각형을 단색 파란색 브러시로 채웁니다.

그 결과 왼쪽에 변환되지 않은 빨간색으로 채워진 사각형과 양식의 오른쪽에 변환된 파란색으로 채워진 사각형이 생성됩니다.

public:
   void SaveRestore3( PaintEventArgs^ e )
   {
      // Translate transformation matrix.
      e->Graphics->TranslateTransform( 100, 0 );

      // Save translated graphics state.
      GraphicsState^ transState = e->Graphics->Save();

      // Reset transformation matrix to identity and fill rectangle.
      e->Graphics->ResetTransform();
      e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), 0, 0, 100, 100 );
      
      // Restore graphics state to translated state and fill second
      // rectangle.
      e->Graphics->Restore( transState );
      e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), 0, 0, 100, 100 );
   }
private void SaveRestore3(PaintEventArgs e)
{

    // Translate transformation matrix.
    e.Graphics.TranslateTransform(100, 0);

    // Save translated graphics state.
    GraphicsState transState = e.Graphics.Save();

    // Reset transformation matrix to identity and fill rectangle.
    e.Graphics.ResetTransform();
    e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 100, 100);

    // Restore graphics state to translated state and fill second

    // rectangle.
    e.Graphics.Restore(transState);
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 100, 100);
}
Private Sub SaveRestore3(ByVal e As PaintEventArgs)

    ' Translate transformation matrix.
    e.Graphics.TranslateTransform(100, 0)

    ' Save translated graphics state.
    Dim transState As GraphicsState = e.Graphics.Save()

    ' Reset transformation matrix to identity and fill rectangle.
    e.Graphics.ResetTransform()
    e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, 100, 100)

    ' Restore graphics state to translated state and fill second

    ' rectangle.
    e.Graphics.Restore(transState)
    e.Graphics.FillRectangle(New SolidBrush(Color.Blue), 0, 0, _
    100, 100)
End Sub

설명

의 메서드를 SaveGraphics호출하면 의 Graphics 상태를 보유하는 정보 블록이 스택에 배치됩니다. 메서드는 Save 해당 정보 블록을 식별하는 을 반환 GraphicsState 합니다. 식별을 GraphicsState 메서드에 Restore 전달하면 정보 블록이 스택에서 제거되고 를 메서드 호출 당시의 Save 상태로 복원 Graphics 하는 데 사용됩니다. 메서드에 GraphicsState 대한 지정된 호출에서 반환된 을 Save 메서드에 Restore 한 번만 전달할 수 있습니다.

메서드에 대한 호출은 Save 중첩될 수 있습니다. 즉, 메서드를 호출하기 전에 메서드를 SaveRestore 여러 번 호출할 수 있습니다. 메서드를 Save 호출할 때마다 정보 블록이 스택에 배치되고 정보 블록에 대한 을 GraphicsState 받습니다. 이러한 개체 중 하나를 메서드 GraphicsRestore 전달하면 는 특정 GraphicsState를 반환한 메서드 호출 당시의 Save 상태로 반환됩니다. 해당 Save 메서드 호출을 통해 스택에 배치된 정보 블록이 스택에서 제거되고 해당 Save 메서드 호출 후 해당 스택에 배치된 모든 정보 블록도 제거됩니다.

메서드에 대한 호출은 BeginContainer 메서드에 대한 호출과 동일한 스택에 정보 블록을 배치합니다 Save . 호출이 Restore 호출 EndContainer 과 쌍을 Save 이루는 것처럼 메서드 호출은 메서드 호출과 쌍을 이릅니다BeginContainer.

메서드를 Restore 호출하면 메서드에 대한 해당 호출 Save 후 스택에 배치된 모든 정보 블록(Save메서드 또는 BeginContainer 메서드)이 스택에서 제거됩니다. 마찬가지로 메서드를 EndContainer 호출하면 메서드에 대한 해당 호출 BeginContainer 후 스택에 배치된 모든 정보 블록(Save메서드 또는 BeginContainer 메서드)이 스택에서 제거됩니다.

적용 대상