브러시 및 그라디언트 작업

XPS 파일의 브러시 및 그라디언트 작업을 위한 C# .NET API 솔루션.

 

.NET API 솔루션용 Aspose.Page를 사용하면 XPS 파일의 벡터 그래픽을 조작할 수 있습니다. 다양한 색상과 질감의 다양한 기하학적 모양을 만들 수 있습니다. 이 페이지에서는 다양한 색상 공간과 그라디언트를 추가하는 방법과 다양한 브러시로 작업하는 방법에 대한 몇 가지 예를 설명합니다. 유추적으로 작업하면 모든 색상의 필요한 기하학적 그림을 만들 수 있습니다.

XPS 파일의 브러시와 그라디언트를 조작하려면 다음이 필요합니다.

  • Aspose.Page for .NET API는 기능이 풍부하고 강력하며 사용하기 쉬운 C# 플랫폼용 문서 조작 및 변환 API입니다.

  • NuGet 패키지 관리자를 열고 Aspose.Page를 검색하여 설치합니다. 패키지 관리자 콘솔에서 다음 명령을 사용할 수도 있습니다.

Package Manager Console Command


    PM> Install-Package Aspose.Page

C# .NET으로 색 공간을 적용하는 단계.

  1. 문서 디렉토리의 경로를 설정하십시오.
  2. XpsDocument Class 를 사용하여 XPS 파일을 만듭니다.
  3. 다른 단색으로 채워진 사각형을 만들려면 XpsPath 클래스의 메서드를 사용합니다.
  4. XPsDocument.Save() 메서드를 사용하여 변경된 XPS 문서를 저장합니다.

XPS 파일의 색상 공간을 설정하는 C# 코드

    using Aspose.Page.XPS;
    using Aspose.Page.XPS.XpsModel;
    using System.Drawing;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithShapes();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // ARGB solid color filled rectangle
    XpsPath rect1 = doc.AddPath(doc.CreatePathGeometry("M 20,10 L 220,10 220,100 20,100 Z"));
    rect1.Fill = doc.CreateSolidColorBrush(doc.CreateColor(Color.FromArgb(222, 12, 15, 159)));

    // ARGB solid color filled rectangle, in another way
    XpsPath rect2 = doc.AddPath(doc.CreatePathGeometry("M 20,210 L 220,210 220,300 20,300 Z"));
    rect2.Fill = doc.CreateSolidColorBrush(doc.CreateColor(222, 12, 15, 159));

    // sRGB solid color filled rectangle
    XpsPath rect3 = doc.AddPath(doc.CreatePathGeometry("M 20,410 L 220,410 220,500 20,500 Z"));
    rect3.Fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));

    // scRGB solid color filled rectangle
    XpsPath rect4 = doc.AddPath(doc.CreatePathGeometry("M 20,610 L 220,610 220,700 20,700 Z"));
    rect4.Fill = doc.CreateSolidColorBrush(doc.CreateColor(0.08706f, 0.04706f, 0.05882f, 0.62353f));

    // CMYK (blue) solid color filled rectangle
    XpsPath rect5 = doc.AddPath(doc.CreatePathGeometry("M 20,810 L 220,810 220,900 20,900 Z"));
    rect5.Fill = doc.CreateSolidColorBrush(
        doc.CreateColor(dataDir + "uswebuncoated.icc", 1.0f, 1.000f, 0.000f, 0.000f, 0.000f));
            
    // Save the resultant XPS document
    doc.Save(dataDir + "ApplyDifferentColorSpaces_out.xps");
다음 코드 조각은 .NET Api 솔루션용 Aspose.Page 내에서 XPS 파일의 시각적 브러시를 사용하는 방법을 보여줍니다.

C#으로 시각적 브러시로 작업하는 단계.

  1. 문서 디렉토리의 경로를 설정하십시오.
  2. XpsDocument 클래스를 사용하여 XPS 파일을 만듭니다.
  3. XpsPathGeometry 클래스를 사용하여 자홍색 격자 비주얼 브러시의 지오메트리를 만듭니다.
  4. 마젠타 그리드 비주얼 브러시의 캔버스를 설정하려면 CreateCanvas() 메서드를 사용합니다.
  5. 비주얼 브러시를 생성하려면 CreateVisualBrush() 메서드를 사용합니다.
  6. XPsDocument.Save() 메서드를 사용하여 변경된 XPS 문서를 저장합니다.

XPS 파일의 시각적 브러시를 조작하는 C# 코드

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithVisualBrush();

    XpsDocument doc = new XpsDocument();
    // Geometry for the magenta grid VisualBrush
    XpsPathGeometry pathGeometry = doc.CreatePathGeometry();
    pathGeometry.AddSegment(doc.CreatePolyLineSegment(
        new PointF[] { new PointF(240f, 5f), new PointF(240f, 310f), new PointF(0f, 310f) }));
    pathGeometry[0].StartPoint = new PointF(0f, 5f);

    // Canvas for the magenta grid VisualBrush
    XpsCanvas visualCanvas = doc.CreateCanvas();

    XpsPath visualPath = visualCanvas.AddPath(
        doc.CreatePathGeometry("M 0,4 L 4,4 4,0 6,0 6,4 10,4 10,6 6,6 6,10 4,10 4,6 0,6 Z"));
    visualPath.Fill = doc.CreateSolidColorBrush(doc.CreateColor(1f, .61f, 0.1f, 0.61f));

    XpsPath gridPath = doc.CreatePath(pathGeometry);
    // Create the Visual Brush, it is specified by some XPS fragment (vector graphics and glyphs)
    gridPath.Fill = doc.CreateVisualBrush(visualCanvas,
        new RectangleF(0f, 0f, 10f, 10f), new RectangleF(0f, 0f, 10f, 10f));
    ((XpsVisualBrush)gridPath.Fill).TileMode = XpsTileMode.Tile;
    // New canvas
    XpsCanvas canvas = doc.AddCanvas();
    canvas.RenderTransform = doc.CreateMatrix(1f, 0f, 0f, 1f, 268f, 70f);
    // Add a grid
    canvas.AddPath(pathGeometry);
    // Red transparent rectangle in the middle top
    XpsPath path = canvas.AddPath(doc.CreatePathGeometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
    path = canvas.AddPath(doc.CreatePathGeometry("M 10,10 L 228,10 228,100 10,100"));
    path.Fill = doc.CreateSolidColorBrush(doc.CreateColor(1.0f, 0.0f, 0.0f));
    path.Opacity = 0.7f;
    // Save the resultant XPS document
    doc.Save(dataDir + "AddGrid_out.xps");

C#으로 수평 그라디언트를 추가하는 단계.

  1. 문서 디렉토리의 경로를 설정하십시오.
  2. XpsDocument 클래스를 사용하여 XPS 파일을 만듭니다.
  3. CreateGradientStop()CreateColor() 가지 메서드를 사용하여 XpsGradentStop 목록을 초기화합니다.
  4. XpsPath 클래스의 메서드를 사용하여 약어 형식으로 지오메트리를 정의하여 새 경로를 만듭니다.
  5. XPsDocument.Save() 메서드를 사용하여 변경된 XPS 문서를 저장합니다.

XPS 파일에 수평 그라디언트를 삽입하는 C# 코드

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithGradient();
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Initialize the List of XpsGradentStop
    List<XpsGradientStop> stops = new List<XpsGradientStop>();
    stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 244, 253, 225), 0.0673828f));
    stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 251, 240, 23), 0.314453f));
    stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 252, 209, 0), 0.482422f));
    stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 241, 254, 161), 0.634766f));
    stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 53, 253, 255), 0.915039f));
    stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 12, 91, 248), 1f));

    // Create a new path by defining the geometery in the abbreviation form
    XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 10,210 L 228,210 228,300 10,300"));
    path.RenderTransform = doc.CreateMatrix(1f, 0f, 0f, 1f, 20f, 70f);
    path.Fill = doc.CreateLinearGradientBrush(new PointF(10f, 0f), new PointF(228f, 0f));
    ((XpsGradientBrush)path.Fill).GradientStops.AddRange(stops);

    // Save the resultant XPS document
    doc.Save(dataDir + "AddHorizontalGradient_out.xps");



자주하는 질문

1. XPS 파일에 그라디언트를 어떻게 추가할 수 있나요?

문서 디렉터리의 경로를 설정합니다. 그라데이션을 추가하려면 CreateColor()CreateGradientStop() 메서드를 사용하세요.

2. XPS 파일에서 시각적 브러시로 작업하는 방법은 무엇입니까?

문서 디렉터리의 경로를 설정합니다. 시각적 브러시를 만들려면 CreateVisualBrush() 메서드를 사용하세요.

3. XPS 파일을 여는 방법? .

Aspose.Page API 솔루션을 사용하여 프로그래밍 방식으로 또는 크로스 플랫폼 XPS 뷰어 를 통해 XPS 열기 파일을 사용하세요.

XPS XPS 파일 형식이란 무엇입니까?

XPS 형식은 PDF 형식과 유사합니다. 둘 다 PDL(페이지 설명 언어) 형식입니다. EPS는 PostScript 언어가 아닌 HTML을 기반으로 합니다. .eps 파일은 문서가 어떻게 생겼는지에 대한 정보와 함께 문서 구조의 마크업을 포함할 수 있습니다. 문서를 인쇄하고 렌더링하는 방법에 대한 지침도 추가되었습니다. 형식의 특징은 문서의 설명을 수정한다는 것입니다. 즉, 누가, 어떤 운영 체제에서 문서를 열더라도 동일하게 보일 것입니다.