Class PdfLinearGradientBrush
Implements linear gradient brush by using PDF axial shading pattern.
Implements
Inherited Members
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfLinearGradientBrush : PdfGradientBrush, ICloneable, IPdfWrapper
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Constructors
PdfLinearGradientBrush(PointF, PointF, PdfColor, PdfColor)
Initializes a new instance of the PdfLinearGradientBrush class.
Declaration
public PdfLinearGradientBrush(PointF point1, PointF point2, PdfColor color1, PdfColor color2)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.PointF | point1 | The starting point of the gradient. |
System.Drawing.PointF | point2 | The end point of the gradient. |
PdfColor | color1 | The starting color of the gradient. |
PdfColor | color2 | The end color of the gradient. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfLinearGradientBrush(RectangleF, PdfColor, PdfColor, PdfLinearGradientMode)
Initializes a new instance of the PdfLinearGradientBrush class.
Declaration
public PdfLinearGradientBrush(RectangleF rect, PdfColor color1, PdfColor color2, PdfLinearGradientMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.RectangleF | rect | A RectangleF structure that specifies the bounds of the linear gradient. |
PdfColor | color1 | The starting color for the gradient. |
PdfColor | color2 | The ending color for the gradient. |
PdfLinearGradientMode | mode | The mode specifies the orientation of the linear gradient |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new RectangleF(0, 0,200, 100), new PdfColor(Color.Red), new PdfColor(Color.Blue), PdfLinearGradientMode.Vertical);
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New RectangleF(0, 0, 200, 100), New PdfColor(Color.Red), New PdfColor(Color.Blue), PdfLinearGradientMode.Vertical)
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfLinearGradientBrush(RectangleF, PdfColor, PdfColor, Single)
Initializes a new instance of the PdfLinearGradientBrush class.
Declaration
public PdfLinearGradientBrush(RectangleF rect, PdfColor color1, PdfColor color2, float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.RectangleF | rect | A RectangleF structure that specifies the bounds of the linear gradient. |
PdfColor | color1 | The starting color for the gradient. |
PdfColor | color2 | The ending color for the gradient. |
System.Single | angle | The angle, measured in degrees clockwise from the x-axis, of the gradient's orientation line. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new RectangleF(0, 0,200, 100), new PdfColor(Color.Red), new PdfColor(Color.Blue), 90);
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New RectangleF(0, 0, 200, 100), New PdfColor(Color.Red), New PdfColor(Color.Blue), 90)
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Properties
Blend
Gets or sets a PdfBlend that specifies positions and factors that define a custom falloff for the gradient.
Declaration
public PdfBlend Blend { get; set; }
Property Value
Type |
---|
PdfBlend |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Create PDF blend
PdfBlend blend = new PdfBlend();
//Set factors
blend.Factors = new float[] {1};
//Set poistions
blend.Positions = new float[] {0};
//Set blend to the brush.
brush.Blend = blend;
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Create PDF blend
Dim blend As New PdfBlend()
'Set factors
blend.Factors = New Single() {1}
'Set poistions
blend.Positions = New Single() {0}
'Set blend to the brush.
brush.Blend = blend
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Extend
Gets or sets the value indicating whether the gradient should extend starting and ending points.
Declaration
public PdfExtend Extend { get; set; }
Property Value
Type |
---|
PdfExtend |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Set the extend mode.
brush.Extend = PdfExtend.Both;
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 300, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Set the extend mode.
brush.Extend = PdfExtend.Both
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 300, 100))
'Get the linear brush bounds.
Dim rect As RectangleF = brush.Rectangle
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
InterpolationColors
Gets or sets a ColorBlend that defines a multicolor linear gradient.
Declaration
public PdfColorBlend InterpolationColors { get; set; }
Property Value
Type |
---|
PdfColorBlend |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Create PDF color blend
PdfColorBlend cblend = new PdfColorBlend();
//Set colors
cblend.Colors = new PdfColor[] { Color.Blue, Color.Red };
//Set poistions
cblend.Positions = new float[] { 0, 1 };
//Set internpolation colors to the brush.
brush.InterpolationColors = cblend;
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Create PDF color blend
Dim cblend As New PdfColorBlend()
'Set colors
cblend.Colors = New PdfColor() { Color.Blue, Color.Red}
'Set poistions
cblend.Positions = New Single() { 0, 1}
'Set internpolation colors to the brush.
brush.InterpolationColors = cblend
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
LinearColors
Gets or sets the starting and ending colors of the gradient.
Declaration
public PdfColor[] LinearColors { get; set; }
Property Value
Type |
---|
PdfColor[] |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
PdfColor startColor = new PdfColor(Color.Black);
PdfColor endColor = new PdfColor(Color.Green);
//Set linear colors.
brush.LinearColors = new PdfColor[] { startColor, endColor };
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
Dim startColor As New PdfColor(Color.Black)
Dim endColor As New PdfColor(Color.Green)
'Set linear colors.
brush.LinearColors = New PdfColor() { startColor, endColor}
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Rectangle
Gets a rectangular region that defines the boundaries of the gradient.
Declaration
public RectangleF Rectangle { get; }
Property Value
Type |
---|
System.Drawing.RectangleF |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
//Get the linear brush bounds.
RectangleF rect = brush.Rectangle;
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 200, 100))
'Get the linear brush bounds.
Dim rect As RectangleF = brush.Rectangle
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Methods
Clone()
Creates a new copy of a brush.
Declaration
public override PdfBrush Clone()
Returns
Type | Description |
---|---|
PdfBrush | A new instance of the Brush class. |
Overrides
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF gradient brush.
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Set the background.
brush.Background = Color.Black;
//Draw rectangle.
graphics.DrawRectangle(brush, new RectangleF(0, 0, 300, 100));
PdfColor startColor = new PdfColor(Color.Black);
PdfColor endColor = new PdfColor(Color.Green);
//Clone the existing linear brush.
PdfLinearGradientBrush cBrush = brush.Clone() as PdfLinearGradientBrush;
//Set linear colors.
cBrush.LinearColors = new PdfColor[] { startColor, endColor };
//Draw rectangle.
graphics.DrawRectangle(cBrush, new RectangleF(0, 150, 300, 100));
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF gradient brush.
Dim brush As New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Set the background.
brush.Background = Color.Black
'Draw rectangle.
graphics.DrawRectangle(brush, New RectangleF(0, 0, 300, 100))
Dim startColor As New PdfColor(Color.Black)
Dim endColor As New PdfColor(Color.Green)
'Clone the existing linear brush.
Dim cBrush As PdfLinearGradientBrush = TryCast(brush.Clone(), PdfLinearGradientBrush)
'Set linear colors.
cBrush.LinearColors = New PdfColor() { startColor, endColor}
'Draw rectangle.
graphics.DrawRectangle(cBrush, New RectangleF(0, 150, 300, 100))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)