Aspose::Words::Drawing::GradientStop class

GradientStop class

Represents one gradient stop. To learn more, visit the Working with Graphic Elements documentation article.

class GradientStop : public System::Object

Methods

MethodDescription
GradientStop(System::Drawing::Color, double)Initializes a new instance of the GradientStop class.
GradientStop(System::Drawing::Color, double, double)Initializes a new instance of the GradientStop class.
Remove()Removes the gradient stop from the parent GradientStopCollection.
get_BaseColor()Gets a value representing the color of the gradient stop without any modifiers.
get_Color()Gets or sets a value representing the color of the gradient stop.
get_Position() constGets or sets a value representing the position of a stop within the gradient expressed as a percent in range 0.0 to 1.0.
get_Transparency() constGets or sets a value representing the transparency of the gradient fill expressed as a percent in range 0.0 to 1.0.
set_Color(System::Drawing::Color)Sets a value representing the color of the gradient stop.
set_Position(double)Sets a value representing the position of a stop within the gradient expressed as a percent in range 0.0 to 1.0.
set_Transparency(double)Sets a value representing the transparency of the gradient fill expressed as a percent in range 0.0 to 1.0.

Examples

Shows how to add gradient stops to the gradient fill.

auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);

System::SharedPtr<Aspose::Words::Drawing::Shape> shape = builder->InsertShape(ShapeType::Rectangle, static_cast<double>(80), static_cast<double>(80));
shape->get_Fill()->TwoColorGradient(System::Drawing::Color::get_Green(), System::Drawing::Color::get_Red(), GradientStyle::Horizontal, GradientVariant::Variant2);

// Get gradient stops collection.
System::SharedPtr<Aspose::Words::Drawing::GradientStopCollection> gradientStops = shape->get_Fill()->get_GradientStops();

// Change first gradient stop.
gradientStops->idx_get(0)->set_Color(System::Drawing::Color::get_Aqua());
gradientStops->idx_get(0)->set_Position(0.1);
gradientStops->idx_get(0)->set_Transparency(0.25);

// Add new gradient stop to the end of collection.
auto gradientStop = System::MakeObject<Aspose::Words::Drawing::GradientStop>(System::Drawing::Color::get_Brown(), 0.5);
gradientStops->Add(gradientStop);

// Remove gradient stop at index 1.
gradientStops->RemoveAt(1);
// And insert new gradient stop at the same index 1.
gradientStops->Insert(1, System::MakeObject<Aspose::Words::Drawing::GradientStop>(System::Drawing::Color::get_Chocolate(), 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops->idx_get(2);
gradientStops->Remove(gradientStop);

ASSERT_EQ(gradientStops->get_Count(), 2);

ASPOSE_ASSERT_EQ(gradientStops->idx_get(0)->get_BaseColor(), System::Drawing::Color::FromArgb(255, 0, 255, 255));
ASSERT_EQ(gradientStops->idx_get(0)->get_Color().ToArgb(), System::Drawing::Color::get_Aqua().ToArgb());
ASSERT_NEAR(gradientStops->idx_get(0)->get_Position(), 0.1, 0.01);
ASSERT_NEAR(gradientStops->idx_get(0)->get_Transparency(), 0.25, 0.01);

ASSERT_EQ(gradientStops->idx_get(1)->get_Color().ToArgb(), System::Drawing::Color::get_Chocolate().ToArgb());
ASSERT_NEAR(gradientStops->idx_get(1)->get_Position(), 0.75, 0.01);
ASSERT_NEAR(gradientStops->idx_get(1)->get_Transparency(), 0.3, 0.01);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
auto saveOptions = System::MakeObject<Aspose::Words::Saving::OoxmlSaveOptions>();
saveOptions->set_Compliance(OoxmlCompliance::Iso29500_2008_Strict);

doc->Save(get_ArtifactsDir() + u"Shape.GradientStops.docx", saveOptions);

See Also