แปรงโค้ดและการไล่ระดับสีของ XPS
โซลูชัน C++ API เพื่อทำงานกับแปรงและการไล่ระดับสีของไฟล์ XPS
โซลูชัน Aspose.Page API สำหรับ C++ ช่วยให้คุณสามารถจัดการกราฟิกแบบเวกเตอร์ของไฟล์ XPS ได้ มันช่วยให้คุณสร้างรูปทรงเรขาคณิตต่างๆ ด้วยสีและพื้นผิวที่แตกต่างกัน เรียนรู้เอกสารประกอบของ Aspose.Page เกี่ยวกับ วิธีทำงานกับแปรง
ในการจัดการกับแปรงและการไล่ระดับสีของไฟล์ XPS เราต้องการ:
Aspose.Page สำหรับ C++ API ซึ่งเป็น API การจัดการเอกสารและการแปลงเอกสารที่มีฟีเจอร์หลากหลาย ทรงพลัง และใช้งานง่ายสำหรับแพลตฟอร์ม C++
คุณสามารถดาวน์โหลดเวอร์ชันล่าสุดได้โดยตรง เพียงเปิดตัวจัดการแพ็คเกจ NuGet แล้วค้นหา Aspose.Page.Cpp แล้วติดตั้ง คุณอาจใช้คำสั่งต่อไปนี้จาก Package Manager Console
Package Manager Console Command
PM> Install-Package Aspose.Page.Cpp
ทำงานกับ Visual Brush ด้วย C++
Aspose.Page สำหรับ C++ API ช่วยให้คุณสามารถเพิ่มตารางให้กับไฟล์ XPS ของคุณโดยใช้โค้ดเพียงไม่กี่บรรทัด ซึ่งสามารถทำได้ทั้งเอกสารใหม่และที่มีอยู่ คลาส XpsVisualBrush ใช้เพื่อตั้งค่าคุณสมบัติของกริด โดยใช้ XpsPathGeometry และ XpsCanvas ออบเจ็กต์ หากต้องการเพิ่มตารางลงในเอกสาร XPS คุณจะต้องทำตามขั้นตอนเหล่านี้:
- การใช้คลาส XpsDocument สร้างวัตถุเอกสาร
- สร้างวัตถุ XpsPathGeometry โดยกำหนดส่วนที่จำเป็น
- ใช้คลาส XpsCanvas เพื่อตั้งค่าการแปลงการเรนเดอร์
- ปรับคุณสมบัติ เติม และ ความทึบ ตามต้องการ
- บันทึกเอกสารโดยการเรียกเมธอด Save()
Namespaces in use
using Aspose::Page::XPS;
using Aspose::Page::XPS::XpsModel;
using System::Drawing;
การใช้แปรงภาพเพื่อสร้างตาราง
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithVisualBrush(); | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
// Geometry for magenta grid VisualBrush | |
System::SharedPtr<XpsPathGeometry> pathGeometry = doc->CreatePathGeometry(); | |
pathGeometry->AddSegment(doc->CreatePolyLineSegment(System::MakeArray<System::Drawing::PointF>({System::Drawing::PointF(240.f, 5.f), System::Drawing::PointF(240.f, 310.f), System::Drawing::PointF(0.f, 310.f)}))); | |
pathGeometry->idx_get(0)->set_StartPoint(System::Drawing::PointF(0.f, 5.f)); | |
// Canvas for magenta grid VisualBrush | |
System::SharedPtr<XpsCanvas> visualCanvas = doc->CreateCanvas(); | |
System::SharedPtr<XpsPath> visualPath = visualCanvas->AddPath(doc->CreatePathGeometry(u"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->set_Fill(doc->CreateSolidColorBrush(doc->CreateColor(1.f, .61f, 0.1f, 0.61f))); | |
System::SharedPtr<XpsPath> gridPath = doc->AddPath(pathGeometry); | |
//Create Visual Brush, it is specified by some XPS fragment (vector graphics and glyphs) | |
gridPath->set_Fill(doc->CreateVisualBrush(visualCanvas, System::Drawing::RectangleF(0.f, 0.f, 10.f, 10.f), System::Drawing::RectangleF(0.f, 0.f, 10.f, 10.f))); | |
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsVisualBrush>(gridPath->get_Fill()))->set_TileMode(Aspose::Page::XPS::XpsModel::XpsTileMode::Tile); | |
// New canvas | |
System::SharedPtr<XpsCanvas> canvas = doc->AddCanvas(); | |
canvas->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 268.f, 70.f)); | |
// Add grid | |
canvas->AddPath(pathGeometry); | |
// Red transparent rectangle in the middle top | |
System::SharedPtr<XpsPath> path = canvas->AddPath(doc->CreatePathGeometry(u"M 30,20 l 258.24,0 0,56.64 -258.24,0 Z")); | |
path = canvas->AddPath(doc->CreatePathGeometry(u"M 10,10 L 228,10 228,100 10,100")); | |
path->set_Fill(doc->CreateSolidColorBrush(doc->CreateColor(1.0f, 0.0f, 0.0f))); | |
path->set_Opacity(0.7f); | |
// Save resultant XPS document | |
doc->Save(dataDir + u"output/" + u"AddGrid_out.xps"); |
เพิ่มการไล่ระดับสีแนวนอนด้วย C++
โซลูชัน Aspose.Page API สำหรับ C++ ช่วยให้คุณสามารถเพิ่มการไล่ระดับสีประเภทต่างๆ ให้กับเอกสาร XPS ของคุณโดยใช้ XpsGradientBrush คลาส คลาสนี้ใช้เพื่อระบุข้อมูล XpsGradientStop และ XpsPath ให้กับอ็อบเจ็กต์ XpsDocument ซึ่งแสดงถึงไฟล์ XPS นี่คือตัวอย่างวิธีการดำเนินการนี้:
- เตรียมใช้งานวัตถุ XpsDocument
- กำหนดพารามิเตอร์ XpsGradientStop และ XpsPath สำหรับเอกสาร XPS
- ตั้งค่าข้อมูลการเรนเดอร์
- บันทึกเอกสารโดยใช้วิธี Save()
แทรกการไล่ระดับสีแนวนอนลงใน XPS
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithGradient(); | |
// Create new XPS Document | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
// Initialize List of XpsGradentStop | |
System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>> stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<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), 1.f)); | |
// Create new path by defining geometery in abbreviation form | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,210 L 228,210 228,300 10,300")); | |
path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f)); | |
path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 0.f), System::Drawing::PointF(228.f, 0.f))); | |
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops); | |
// Save resultant XPS document | |
doc->Save(dataDir + u"output/" + u"AddHorizontalGradient_outXPS.xps"); |
XPS XPS รูปแบบไฟล์คืออะไร
รูปแบบ XPS คล้ายกับรูปแบบ PDF ทั้งสองรูปแบบเป็นภาษาคำอธิบายหน้า (PDL) EPS อิงตาม HTML ไม่ใช่ภาษา PostScript ไฟล์ .eps สามารถใส่มาร์กอัปของโครงสร้างของเอกสารพร้อมกับข้อมูลเกี่ยวกับลักษณะของเอกสารได้ นอกจากนี้ยังมีคำแนะนำเพิ่มเติมเกี่ยวกับวิธีการพิมพ์และแสดงผลเอกสาร คุณสมบัติของรูปแบบคือ แก้ไขคำอธิบายของเอกสาร ซึ่งหมายความว่าจะมีลักษณะเหมือนกันไม่ว่าใครจะเปิดจากระบบปฏิบัติการใด