Trabajar con degradado | Solución API C++

Agregar degradado en un documento XPS

Agregar degradado horizontal

Aspose.Page para C++ le permite agregar degradado horizontal a un documento XPS. La clase XpsGrandientBrush se utiliza para especificar la información XpsGradientStop y XpsPath en el objeto XpsDocument que representa el archivo XPS. El siguiente código C++ muestra cómo agregar información de degradado horizontal a un documento.

  1. Cree un objeto de la clase XpsDocument
  2. Agregue XpsPath al documento XPS
  3. Establecer la información de renderizado
  4. Utilice CreateLinearGradientBrush del documento XPS para crear un pincel de degradado. Luego configura este pincel para rellenar.
  5. Utilice set_GradientStops para configurar XpsGradientStop para el pincel.
  6. Guarde el documento
 1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2// Create new XPS Document
 3auto doc = System::MakeObject<XpsDocument>();
 4// Initialize List of XpsGradentStop
 5System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>> stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>();
 6stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 244, 253, 225), 0.0673828f));
 7stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 251, 240, 23), 0.314453f));
 8stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 252, 209, 0), 0.482422f));
 9stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 241, 254, 161), 0.634766f));
10stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 53, 253, 255), 0.915039f));
11stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 12, 91, 248), 1.f));
12// Create new path by defining geometery in abbreviation form
13System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,210 L 228,210 228,300 10,300"));
14path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f));
15path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 0.f), System::Drawing::PointF(228.f, 0.f)));
16(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops);
17// Save resultant XPS document
18doc->Save(outDir() + u"AddHorizontalGradient_out.xps");

Agregar degradado vertical

Así como puede agregar el degradado horizontal, puede usar Aspose.Page para C++ para agregar información del degradado vertical al documento XPS. El siguiente ejemplo de código C++ muestra cómo agregar un degradado vertical a un documento XPS.

 1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2// Create new XPS Document
 3auto doc = System::MakeObject<XpsDocument>();
 4// Initialize List of XpsGradentStop
 5auto stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>();
 6stops->Add(doc->CreateGradientStop(doc->CreateColor(253, 255, 12, 0), 0.f));
 7stops->Add(doc->CreateGradientStop(doc->CreateColor(252, 255, 154, 0), 0.359375f));
 8stops->Add(doc->CreateGradientStop(doc->CreateColor(252, 255, 56, 0), 0.424805f));
 9stops->Add(doc->CreateGradientStop(doc->CreateColor(253, 255, 229, 0), 0.879883f));
10stops->Add(doc->CreateGradientStop(doc->CreateColor(252, 255, 255, 234), 1.f));
11// Create new path by defining geometery in abbreviation form
12System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,110 L 228,110 228,200 10,200"));
13path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f));
14path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 110.f), System::Drawing::PointF(10.f, 200.f)));
15(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops);
16// Save resultant XPS document
17doc->Save(outDir() + u"AddVerticalGradient_out.xps");

Agregar degradado lineal

También puede agregar un degradado lineal a un documento XPS usando Aspose.Page para C++ como se muestra en el siguiente ejemplo de código.

 1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2// Create new XPS Document
 3auto doc = System::MakeObject<XpsDocument>();
 4// Initialize List of XpsGradentStop
 5System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>> stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>();
 6// Add Colors to Gradient
 7stops->Add(doc->CreateGradientStop(doc->CreateColor(0, 142, 4), 0.f));
 8stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 202, 0), 0.144531f));
 9stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 250, 0), 0.264648f));
10stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 0, 0), 0.414063f));
11stops->Add(doc->CreateGradientStop(doc->CreateColor(233, 0, 255), 0.544922f));
12stops->Add(doc->CreateGradientStop(doc->CreateColor(107, 27, 190), 0.694336f));
13stops->Add(doc->CreateGradientStop(doc->CreateColor(63, 0, 255), 0.844727f));
14stops->Add(doc->CreateGradientStop(doc->CreateColor(0, 199, 80), 1.f));
15// Create new path by defining geometery in abbreviation form
16System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,10 L 228,10 228,100 10,100"));
17path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f));
18path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 10.f), System::Drawing::PointF(228.f, 100.f)));
19(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops);
20// Save resultant XPS document
21doc->Save(outDir() + u"AddLinearGradient_out.xps");

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.