Trabalhar com Gradiente | Solução API C++

Adicionar Gradiente em Documento XPS

Adicionar Gradiente Horizontal

O Aspose.Page para C++ permite adicionar gradiente horizontal a um documento XPS. A classe XpsGrandientBrush é utilizada para especificar a informação XpsGradientStop e XpsPath para o objeto XpsDocument que representa o ficheiro XPS. O código C++ seguinte mostra como adicionar informação de gradiente horizontal a um documento.

  1. Crie um objeto da classe XpsDocument
  2. Adicione XpsPath ao documento XPS
  3. Defina as informações de renderização
  4. Utilize CreateLinearGradientBrush do documento XPS para criar um pincel de gradiente. Em seguida, defina este pincel para preenchimento.
  5. Utilize set_GradientStops para definir XpsGradientStop para o pincel.
  6. Guarde o 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");

Adicionar Gradiente Vertical

Tal como pode adicionar o gradiente horizontal, pode utilizar o Aspose. Page para C++ para adicionar informações de gradiente vertical ao documento XPS. O exemplo de código C++ seguinte mostra como adicionar um gradiente vertical a um 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");

Adicionar Gradiente Linear

Também pode adicionar gradiente linear a um documento XPS utilizando o Aspose.Page para C++, como mostrado no exemplo de código seguinte.

 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.