Class PdfLinearGradientBrush
- Namespace
- Syncfusion.Pdf.Graphics
- Assembly
- Syncfusion.Pdf.Portable.dll
Implements linear gradient brush by using PDF axial shading pattern.
public class PdfLinearGradientBrush : PdfGradientBrush, ICloneable
- Inheritance
-
PdfLinearGradientBrush
- Implements
- Inherited Members
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.
public PdfLinearGradientBrush(PointF point1, PointF point2, PdfColor color1, PdfColor color2)
Parameters
point1
PointFThe starting point of the gradient.
point2
PointFThe end point of the gradient.
color1
PdfColorThe starting color of the gradient.
color2
PdfColorThe 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.
public PdfLinearGradientBrush(RectangleF rect, PdfColor color1, PdfColor color2, PdfLinearGradientMode mode)
Parameters
rect
RectangleFA RectangleF structure that specifies the bounds of the linear gradient.
color1
PdfColorThe starting color for the gradient.
color2
PdfColorThe ending color for the gradient.
mode
PdfLinearGradientModeThe 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, float)
Initializes a new instance of the PdfLinearGradientBrush class.
public PdfLinearGradientBrush(RectangleF rect, PdfColor color1, PdfColor color2, float angle)
Parameters
rect
RectangleFA RectangleF structure that specifies the bounds of the linear gradient.
color1
PdfColorThe starting color for the gradient.
color2
PdfColorThe ending color for the gradient.
angle
floatThe 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.
public PdfBlend Blend { get; set; }
Property Value
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.
public PdfExtend Extend { get; set; }
Property Value
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.
public PdfColorBlend InterpolationColors { get; set; }
Property Value
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.
public PdfColor[] LinearColors { get; set; }
Property Value
- 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.
public RectangleF Rectangle { get; }
Property Value
- 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.
public override PdfBrush Clone()
Returns
- PdfBrush
A new instance of the Brush class.
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)