Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Colors and Color Spaces

The ColorBase abstract class is used to encapsulate colors in different color spaces. The classes which inherit from ColorBase:

SimpleColor

The abstract SimpleColor represents colors, which are defined with color components. The following classes inherit SimpleColor:

RgbColor

Represents an ARGB (alpha, red, green, blue) color. The RgbColor class exposes the following properties:

  • A: The alpha component value.
  • R: The red component value.
  • G: The green component value.
  • B: The blue component value.

Example 1 demonstrates how you can create an RgbColor and assign it as Fill of a Path element.

Example 1: Create RgbColor

RgbColor magenta = new RgbColor(255, 0, 255); 
Path path = new Path(); 
path.Fill = magenta; 

PatternColor

The abstract PatternColor class represents colors, which are defined with the pattern color space. A pattern color paints with a pattern rather than a single color. PatternColor is inherited by the Gradient and TilingBase classes.

Gradient

Gradient provides a smooth transition between colors across an area which is painted. The gradient color is represented by the Gradient abstract class which exposes the following properties:

  • StartPoint: A Point object representing the starting two-dimensional coordinates of the gradient.

  • EndPoint: A Point object representing the ending two-dimensional coordinates of the gradient.

  • ExtendBefore: Specifies whether to extend the gradient beyond the starting point.

  • ExtendAfter: Specifies whether to extend the gradient beyond the ending point.

  • Background: SimpleColor object representing the background color.

  • GradientStops: A collection of GradientStop objects representing the gradient stops collection.

The Gradient class is inherited by the following classes:

  • LinearGradient: Defines a color blend along a line between two points, optionally extended beyond the boundary points by continuing the boundary colors.

    Example 2 shows how to create a LinearGradient and assign it as the FillColor of a FixedContentEditor.

    Example 2: Create LinearGradient

        FixedContentEditor containerEditor = new FixedContentEditor(container); 
     
        LinearGradient linearGradient = new LinearGradient(new Point(0, 0), new Point(30, 30)); 
        linearGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 207, 0), 0)); 
        linearGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 102, 204), 1)); 
     
        containerEditor.GraphicProperties.FillColor = linearGradient; 
        containerEditor.DrawRectangle(new Rect(10, 10, 48, 29)); 
    

    The gradient created in Example 2 is shown in Figure 1.

    Figure 1: LinearGradient

    Rad Pdf Processing Concepts Colors And Color Spaces 01

  • RadialGradient: Defines a blend between two circles, optionally extended beyond the boundary circles by continuing the boundary colors. The RadialGradient class exposes the following properties:

    • StartRadius: Decimal number determining the radius of the starting circle.
    • EndRadius: Decimal number determining the radius of the ending circle.

    Example 3 demonstrates how to create a RadialGradient and assing it as the FillColor of a FixedContentEditor.

    Example 3: Create RadialGradient

        FixedContentEditor containerEditor = new FixedContentEditor(container); 
     
        RadialGradient radialGradient = new RadialGradient(new Point(40, 40), new Point(40, 40), 0, 30); 
        radialGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 207, 0), 0)); 
        radialGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 102, 204), 1)); 
     
        containerEditor.GraphicProperties.FillColor = radialGradient; 
        containerEditor.DrawEllipse(new Point(40, 40), 30, 30); 
    

    The result from Example 3 is shown in Figure 2.

    Figure 2: RadialGradient

    Rad Pdf Processing Concepts Colors And Color Spaces 03

Tiling Pattern

A tiling pattern consists of a small graphical figure called a pattern cell. Painting with the pattern replicates the cell at fixed horizontal and vertical intervals to fill an area. The tiling pattern is represented by the TilingBase abstract class, which exposes the following properties:

  • BoundingBox: Property of type Rect representing the dimensions pattern cell.

  • VerticalSpacing: Decimal number determining the vertical spacing between pattern cells.

  • HorizontalSpacing: Decimal number determining the horizontal spacing between pattern cells.

  • Size: The size of the bounding box.

  • Content: The collection of content elements inside a pattern cell.

  • Position: The position of the tiling pattern.

  • TilingType: Property of type TilingType that represents the tiling type.The possible values are:

    • AllowSmallDistortion: Pattern cells are spaces consistently. To achieve this, the pattern cell might be slightly distorted by making small adjustments to the HorizontalSpacing and VerticalSpacing.
    • NoDistortion: Pattern cells are not distorted, but the spacing between pattern cells may vary. This achieves the spacing requested by HorizontalSpacing and VerticalSpacing on average, but not necessarily for each individual pattern cell.
    • FastTiling: Pattern cells are spaced consistently as in AllowSmallDistortion type but with additional distortion permitted to enable a more efficient painting.

The TilingBase class is inherited from the following classes:

  • Tiling: Represents a tiling pattern.

  • UncoloredTiling: Represents an uncolored tiling pattern. This type of tiling patterns can be defined with some specific content, and then reused with a different color of their content. It exposes two additional properties - Tiling which represents the tiling to be used and Color representing the color of the content of the specified tiling.

Since the TilingBase class implements the IContentRootElement interface like RadFixedPage, the content of the tiling can be modified using the FixedContentEditor class. Example 4 shows how a tiling pattern can be created.

Example 4: Create tiling

FixedContentEditor containerEditor = new FixedContentEditor(container); 
 
Tiling tiling = new Tiling(new Rect(0, 0, 10, 10)); 
FixedContentEditor tilingEditor = new FixedContentEditor(tiling); 
tilingEditor.GraphicProperties.IsStroked = false; 
tilingEditor.GraphicProperties.FillColor = new RgbColor(128, 28, 43); 
tilingEditor.DrawRectangle(new Rect(2, 2, 5, 7)); 
 
containerEditor.GraphicProperties.FillColor = tiling; 
containerEditor.DrawCircle(new Point(30, 30), 20); 

The tiling created in Example 4 is shown in Figure 3.

Figure 3: Tiling

Rad Pdf Processing Concepts Colors And Color Spaces 02

See Also

In this article