그래픽 상태 작업
PS 파일의 그래픽 상태 클립 및 변환
PS 문서(XPS의 캔버스와 동일)에서 그래픽 상태를 관리하는 것은 Aspose.Page for .NET에서 제공하는 주요 기능 중 하나입니다. 아래 예에서는 다음을 수행하는 방법을 알아봅니다.
현재 그래픽 상태를 저장하고 새 그래픽 상태를 생성한 후 현재로 설정합니다.
현재 그래픽 상태를 변환, 크기 조정, 회전 또는 전단합니다.
현재 그래픽 상태에 대한 복잡한 변환을 설정합니다.
현재 그래픽 상태에 대한 페인트 및 획을 설정합니다.
그래픽 경로를 채우고 그립니다.
그래픽 상태를 클립합니다.
이전 그래픽 상태를 복원합니다.
PS 파일의 그래픽 상태를 변환하려면 다음 가이드를 따르십시오.
- PsDocument 클래스 를 사용하여 PS 파일을 만듭니다.
- 직사각형 그래픽 경로를 만듭니다.
- 현재 그래픽 상태를 저장하고 새 그래픽 상태를 생성한 후 WriteGraphicsSave() 를 사용하여 현재로 설정합니다 방법.
- Translate() 메서드를 사용하여 현재 그래픽 상태를 변환합니다.
- SetPaint() 메서드를 사용하여 현재 그래픽 상태에서 페인트를 설정합니다.
- Fill() 메서드를 사용하여 그래픽 경로를 채웁니다.
- WriteGraphicsRestore 메서드를 사용하여 이전 그래픽 상태를 복원합니다.
- Scale() 을 사용하여 다른 변환으로 더 많은 그래픽 상태를 추가하려면 3~7단계를 반복합니다. Rotate() , Shear() 및 Transform() 행동 양식.
- ClosePage() 메서드를 사용하여 현재 페이지를 닫습니다.
- 생성된 PS 문서를 PsDocument.Save() 메서드를 사용하여 저장합니다.
PS 파일 그래픽 상태 변환 C# 코드
using Aspose.Page.EPS;
using Aspose.Page.EPS.Device;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
//Create output stream for PostScript document
using (Stream outPsStream = new FileStream(dataDir + "Transformations_outPS.ps", FileMode.Create))
{
//Create save options with default values
PsSaveOptions options = new PsSaveOptions();
// Create new 1-paged PS Document
PsDocument document = new PsDocument(outPsStream, options, false);
//Create graphics path from the rectangle
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddRectangle(new System.Drawing.RectangleF(0, 0, 150, 100));
///////////////////// Translation //////////////////////////////////////////////////////////////////////
//Save graphics state in order to return back to this state after transformation
document.WriteGraphicsSave();
//Displace current graphics state on 250 to the right. So we add translation component to the current transformation.
document.Translate(250, 0);
//Set paint in the current graphics state
document.SetPaint(new System.Drawing.SolidBrush(Color.Blue));
//Fill the second rectangle in the current graphics state (has translation transformation)
document.Fill(path);
//Restore graphics state to the previus (upper) level
document.WriteGraphicsRestore();
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Displace on 200 to the bottom.
document.Translate(0, 200);
////////////////////// Scaling //////////////////////////////////////////////////////////////////////////
//Save graphics state in order to return back to this state after transformation
document.WriteGraphicsSave();
//Scale current graphics state on 0.5 in X axis and on 0.75f in Y axis. So we add scale component to the current transformation.
document.Scale(0.5f, 0.75f);
//Set paint in the current graphics state
document.SetPaint(new System.Drawing.SolidBrush(Color.Red));
//Fill the third rectangle in the current graphics state (has scale transformation)
document.Fill(path);
//Restore graphics state to the previus (upper) level
document.WriteGraphicsRestore();
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Displace upper level graphics state on 250 to the right.
document.Translate(250, 0);
////////////////////// Rotation //////////////////////////////////////////////////////////////////////
//Save graphics state in order to return back to this state after transformation
document.WriteGraphicsSave();
//Rotate current graphics state on 45 degrees around origin of current graphics state (350, 300). So we add rotation component to the current transformation.
document.Rotate(45);
//Set paint in the current graphics state
document.SetPaint(new System.Drawing.SolidBrush(Color.Green));
//Fill the fourth rectangle in the current graphics state (has rotation transformation)
document.Fill(path);
//Restore graphics state to the previus (upper) level
document.WriteGraphicsRestore();
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Returns upper level graphics state back to the left and displace on 200 to the bottom.
document.Translate(-250, 200);
////////////////////// Shearing //////////////////////////////////////////////////////////////////////
//Save graphics state in order to return back to this state after transformation
document.WriteGraphicsSave();
//Shear current graphics state. So we add shear component to the current transformation.
document.Shear(0.1f, 0.2f);
//Set paint in the current graphics state
document.SetPaint(new System.Drawing.SolidBrush(Color.Pink));
//Fill the fifth rectangle in the current graphics state (has shear transformation)
document.Fill(path);
//Restore graphics state to the previus (upper) level
document.WriteGraphicsRestore();
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Displace upper level graphics state on 250 to the right.
document.Translate(250, 0);
////////////////////// Complex transformation ////////////////////////////////////////////////////////
//Save graphics state in order to return back to this state after transformation
document.WriteGraphicsSave();
//Transform current graphics state with complex transformation. So we add translation, scale and rotation components to the current transformation.
document.Transform(new System.Drawing.Drawing2D.Matrix(1.2f, -0.965925f, 0.258819f, 1.5f, 0f, 50));
//Set paint in the current graphics state
document.SetPaint(new System.Drawing.SolidBrush(Color.Aquamarine));
//Fill the sixth rectangle in the current graphics state (has complex transformation)
document.Fill(path);
//Restore graphics state to the previus (upper) level
document.WriteGraphicsRestore();
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Close current page
document.ClosePage();
//Save the document
document.Save();
}
PS 파일의 그래픽 상태에 클립을 추가하려면 다음 가이드를 따르십시오.
- PsDocument 클래스 를 사용하여 PS 파일을 만듭니다.
- 직사각형 그래픽 경로를 만듭니다.
- 현재 그래픽 상태를 저장하고 새 그래픽 상태를 생성한 후 WriteGraphicsSave() 를 사용하여 현재로 설정합니다 방법.
- Translate() 메서드를 사용하여 현재 그래픽 상태를 변환합니다.
- 원형 그래픽 경로를 만듭니다.
- Clip() 메서드를 사용하여 현재 그래픽 상태에 원별 클리핑을 추가합니다.
- SetPaint() 메서드를 사용하여 현재 그래픽 상태에서 페인트를 설정합니다.
- Fill() 메서드를 사용하여 직사각형 그래픽 경로를 채웁니다.
- WriteGraphicsRestore() 메서드를 사용하여 이전 그래픽 상태를 복원합니다.
- Translate() 메서드를 사용하여 현재 그래픽 상태를 변환합니다.
- System.Drawing.펜 개체를 만듭니다.
- SetStroke() 메서드를 사용하여 현재 그래픽 상태에서 스트로크를 설정합니다.
- Draw() 메서드를 사용하여 잘린 직사각형 위에 직사각형 그래픽 경로를 그립니다.
- ClosePage() 메서드를 사용하여 현재 페이지를 닫습니다.
- PsDocument.Save() 메서드를 사용하여 생성된 PS 문서를 저장합니다.
PS 파일 그래픽 상태 클리핑 C# 코드
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
//Create output stream for PostScript document
using (Stream outPsStream = new FileStream(dataDir + "Clipping_outPS.ps", FileMode.Create))
{
//Create save options with default values
PsSaveOptions options = new PsSaveOptions();
// Create new 1-paged PS Document
PsDocument document = new PsDocument(outPsStream, options, false);
//Create graphics path from the rectangle
System.Drawing.Drawing2D.GraphicsPath rectangePath = new System.Drawing.Drawing2D.GraphicsPath();
rectangePath.AddRectangle(new System.Drawing.RectangleF(0, 0, 300, 200));
////////////////////// Clipping by shape //////////////////////////////////////////////////////////////////////
//Save graphics state in order to return back to this state after transformation
document.WriteGraphicsSave();
//Displace current graphics state on 100 points to the right and 100 points to the bottom.
document.Translate(100, 100);
//Create graphics path from the circle
System.Drawing.Drawing2D.GraphicsPath circlePath = new System.Drawing.Drawing2D.GraphicsPath();
circlePath.AddEllipse(new System.Drawing.RectangleF(50, 0, 200, 200));
//Add clipping by circle to the current graphics state
document.Clip(circlePath);
//Set paint in the current graphics state
document.SetPaint(new System.Drawing.SolidBrush(Color.Blue));
//Fill the rectangle in the current graphics state (with clipping)
document.Fill(rectangePath);
//Restore graphics state to the previus (upper) level
document.WriteGraphicsRestore();
//Displace upper level graphics state on 100 points to the right and 100 points to the bottom.
document.Translate(100, 100);
Pen pen = new Pen(new SolidBrush(Color.Blue), 2);
pen.DashStyle = DashStyle.Dash;
document.SetStroke(pen);
//Draw the rectangle in the current graphics state (has no clipping) above clipped rectngle
document.Draw(rectangePath);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Close current page
document.ClosePage();
//Save the document
document.Save();
}
자주하는 질문
1. PostScript(PS) 문서의 그래픽 상태란 무엇입니까?
PostScript의 그래픽 상태는 문서 내의 그래픽 요소에 적용되는 현재 설정 및 속성입니다. 여기에는 현재 변환 행렬, 선 스타일, 채우기 색상, 클리핑 경로 및 페이지에서 요소가 렌더링되는 방식에 영향을 미치는 기타 그래픽 속성과 같은 매개변수가 포함됩니다.
2. PS 문서의 그래픽 상태를 어떻게 관리할 수 있습니까?
이는 gsave
및 grestore
와 같은 PostScript 명령을 사용하여 각각 그래픽 상태를 저장하고 복원할 수 있습니다. 또한 setlinewidth
, setrgbcolor
및 setdash
와 같은 연산자를 사용하여 필요에 따라 그래픽 상태의 특정 속성을 수정할 수 있습니다.
3. PostScript(PS) 문서의 그래픽 상태를 이해하고 관리하는 것이 왜 중요한가요?
그래픽 상태를 조작하면 변형, 색상 변경, 영역 자르기 등의 효과를 얻을 수 있어 그래픽이 디자인 사양에 따라 올바르게 표시되도록 할 수 있습니다. 또한 특히 복잡하거나 반복적인 그래픽 요소를 처리할 때 파일 크기와 성능을 최적화하는 데 도움이 됩니다.
PS PS 파일 형식이란 무엇입니까?
PS 형식은 PDL(페이지 설명 언어) 형식 중 하나입니다. 페이지에 그래픽 및 텍스트 정보를 포함할 수 있습니다. 그렇기 때문에 대부분의 이미지 편집 프로그램에서 이 형식을 지원했습니다. 포스트스크립트 파일 자체는 일종의 프린터 지침입니다. 여기에는 해당 페이지에서 인쇄할 내용과 방법에 대한 정보가 포함되어 있습니다.