Lavorare con il gradiente | Soluzione API C++

Aggiungi sfumatura in un documento XPS

Aggiungi sfumatura orizzontale

Aspose.Page per C++ consente di aggiungere una sfumatura orizzontale a un documento XPS. La classe XpsGrandientBrush viene utilizzata per specificare le informazioni XpsGradientStop e XpsPath all’oggetto XpsDocument che rappresenta il file XPS. Il seguente codice C++ mostra come aggiungere informazioni sulla sfumatura orizzontale a un documento.

  1. Crea un oggetto di classe XpsDocument
  2. Aggiungi XpsPath al documento XPS
  3. Imposta le informazioni di rendering
  4. Utilizza CreateLinearGradientBrush del documento XPS per creare un pennello sfumato. Quindi imposta questo pennello su Riempimento.
  5. Utilizza set_GradientStops per impostare XpsGradientStop per il pennello.
  6. Salva il 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");

Aggiungi sfumatura verticale

Proprio come puoi aggiungere una sfumatura orizzontale, puoi usare Aspose.Page per C++ per aggiungere informazioni sulla sfumatura verticale al documento XPS. Il seguente esempio di codice C++ mostra come aggiungere una sfumatura verticale 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");

Aggiungi sfumatura lineare

È anche possibile aggiungere una sfumatura lineare a un documento XPS utilizzando Aspose.Page per C++, come mostrato nel seguente esempio di codice.

 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.