다음을 통해 공유


Graphics::Restore 메서드(gdiplusgraphics.h)

Graphics::Restore 메서드는 이 Graphics 개체의 Graphics::Save 메서드에 대한 이전 호출에서 저장한 상태로 이 Graphics 개체의 상태를 설정합니다.

구문

Status Restore(
  [in] GraphicsState gstate
);

매개 변수

[in] gstate

형식: GraphicsState

저장된 상태 블록을 식별하는 32비트 값(이 Graphics 개체의 Graphics::Save 메서드에 대한 이전 호출에서 반환됨).

반환 값

형식: 상태

메서드가 성공하면 Status 열거형의 요소인 Ok를 반환합니다.

메서드가 실패하면 Status 열거형의 다른 요소 중 하나를 반환합니다.

설명

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

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

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

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

예제

다음 예제에서는 Graphics::Restore 메서드를 사용하는 두 가지 방법을 보여 줍니다. 첫 번째 예제에서는 중첩된 저장된 상태를 복원하는 방법을 보여 하며, 두 번째 예제에서는 두 개의 중첩된 저장된 상태 중 첫 번째 상태만 복원하는 방법을 보여 있습니다.

중첩된 저장된 상태 복원

다음 예제에서는 Graphics 개체의 월드 변환을 회전으로 설정한 다음 Graphics 개체의 상태를 저장합니다. 다음으로 코드는 TranslateTransform을 호출하고 상태를 다시 저장합니다. 그런 다음 코드는 ScaleTransform을 호출합니다. 이 시점에서 Graphics 개체의 월드 변환은 복합 변환입니다. 먼저 회전한 다음 변환한 다음 크기를 조정합니다. 이 코드는 빨간색 펜을 사용하여 해당 복합 변환으로 변환되는 타원을 그립니다.

이 코드는 Save에 대한 두 번째 호출에서 반환된 state2Graphics::Restore 메서드에 전달하고 녹색 펜을 사용하여 줄임표를 다시 그립니다. 녹색 타원은 회전 및 변환되지만 크기는 조정되지 않습니다. 마지막으로 코드는 Save에 대한 첫 번째 호출에서 반환된 state1을 Graphics::Restore 메서드에 전달하고 파란색 펜을 사용하여 줄임표를 다시 그립니다. 파란색 타원은 회전되지만 변환되거나 크기가 조정되지 않습니다.

VOID Example_Save1(HDC hdc)
{
   Graphics graphics(hdc);
   GraphicsState state1, state2;

   graphics.RotateTransform(30.0f);
   state1 = graphics.Save();
   graphics.TranslateTransform(100.0f, 0.0f, MatrixOrderAppend);
   state2 = graphics.Save();
   graphics.ScaleTransform(1.0f, 3.0f, MatrixOrderAppend);
   
   // Draw an ellipse. 
   // Three transformations apply: rotate, then translate, then scale.
   Pen redPen(Color(255, 255, 0, 0));
   graphics.DrawEllipse(&redPen, 0, 0, 100, 20);
 
   // Restore to state2 and draw the ellipse again. 
   // Two transformations apply: rotate then translate.
   graphics.Restore(state2);
   Pen greenPen(Color(255, 0, 255, 0));
   graphics.DrawEllipse(&greenPen, 0, 0, 100, 20);

   // Restore to state1 and draw the ellipse again. 
   // Only the rotation transformation applies.
   graphics.Restore(state1);
   Pen bluePen(Color(255, 0, 0, 255));
   graphics.DrawEllipse(&bluePen, 0, 0, 100, 20);
}

두 개의 중첩된 저장된 상태 중 첫 번째 상태만 복원

다음 예제에서는 Graphics 개체의 월드 변환을 회전으로 설정한 다음 Graphics 개체의 상태를 저장합니다. 다음으로 코드는 TranslateTransform을 호출하고 상태를 다시 저장합니다. 그런 다음 코드는 ScaleTransform을 호출합니다. 이 시점에서 Graphics 개체의 월드 변환은 복합 변환입니다. 먼저 회전한 다음 변환한 다음 크기를 조정합니다. 이 코드는 빨간색 펜을 사용하여 해당 복합 변환으로 변환되는 타원을 그립니다.

코드는 Save에 대한 첫 번째 호출에서 반환된 state1Graphics::Restore 메서드에 전달하고 녹색 펜을 사용하여 줄임표를 다시 그립니다. 녹색 타원은 회전되지만 변환되거나 크기가 조정되지 않습니다.

다음으로 코드는 state2로 식별된 상태를 복원하려고 시도합니다. Restore(state1) 호출이 스택에서 state1state2 로 식별되는 정보 블록을 제거했기 때문에 시도가 실패합니다.

VOID Example_Save2(HDC hdc)
{
   Graphics graphics(hdc);
   GraphicsState state1, state2;

   graphics.RotateTransform(30.0f);
   state1 = graphics.Save();
   graphics.TranslateTransform(100.0f, 0.0f, MatrixOrderAppend);
   state2 = graphics.Save();
   graphics.ScaleTransform(1.0f, 3.0f, MatrixOrderAppend);
   
   // Draw an ellipse. 
   // Three transformations apply: rotate, then translate, then scale.
   Pen redPen(Color(255, 255, 0, 0));
   graphics.DrawEllipse(&redPen, 0, 0, 100, 20);
 
   // Restore to state1 and draw the ellipse again. 
   // Only the rotation transformation applies.
   graphics.Restore(state1);
   Pen greenPen(Color(255, 0, 255, 0));
   graphics.DrawEllipse(&greenPen, 0, 0, 100, 20);

   // The information block identified by state2 has been lost.
   // The following call to Restore has no effect because
   // Restore(state1) removed from the stack the
   // information blocks identified by state1 and state2.
   graphics.Restore(state2);

   // The Graphics object is still in the state identified by state1.
   // The following code draws a blue ellipse on top of the previously
   // drawn green ellipse.
   Pen bluePen(Color(255, 0, 0, 255));
   graphics.DrawEllipse(&bluePen, 0, 0, 100, 20);
}

요구 사항

   
지원되는 최소 클라이언트 Windows XP, Windows 2000 Professional [데스크톱 앱만 해당]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 gdiplusgraphics.h(Gdiplus.h 포함)
라이브러리 Gdiplus.lib
DLL Gdiplus.dll

참고 항목

그래픽

그래픽::저장