Ecng.Drawing 1.0.167

dotnet add package Ecng.Drawing --version 1.0.167
                    
NuGet\Install-Package Ecng.Drawing -Version 1.0.167
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ecng.Drawing" Version="1.0.167" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Drawing" Version="1.0.167" />
                    
Directory.Packages.props
<PackageReference Include="Ecng.Drawing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ecng.Drawing --version 1.0.167
                    
#r "nuget: Ecng.Drawing, 1.0.167"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ecng.Drawing@1.0.167
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ecng.Drawing&version=1.0.167
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Drawing&version=1.0.167
                    
Install as a Cake Tool

Ecng.Drawing

A lightweight, cross-platform drawing primitives library for .NET applications. Provides essential graphics utilities, color handling, brush abstractions, and UI layout helpers without heavy dependencies.

Table of Contents

Installation

Add a reference to the Ecng.Drawing project or NuGet package in your .NET application.

<ProjectReference Include="path\to\Ecng.Drawing\Drawing.csproj" />

Key Features

  • Color Utilities: Convert between ARGB integers, HTML color strings, and System.Drawing.Color
  • Brush Abstractions: Solid and gradient brush implementations for graphics rendering
  • Layout Primitives: Thickness, alignment enums for UI layout
  • Drawing Styles: Comprehensive set of chart and visualization styles
  • Cross-Platform: Supports .NET Standard 2.0, .NET 6.0, and .NET 10.0
  • Lightweight: Minimal dependencies, no heavy graphics frameworks required

API Reference

Color Conversions

The DrawingExtensions class provides extension methods for working with colors.

ToColor(int argb)

Converts an ARGB integer to a Color object.

int argbValue = -16776961; // Blue color
Color color = argbValue.ToColor();
ToColor(string htmlColor)

Converts an HTML color string to a Color object. Supports multiple formats:

  • #RRGGBB - 6-digit hex (e.g., #FF5733)
  • #RGB - 3-digit hex shorthand (e.g., #F53)
  • Named colors (e.g., "Red", "LightGrey")
Color red = "#FF0000".ToColor();
Color blue = "#00F".ToColor();
Color gray = "LightGrey".ToColor(); // Special case handling
ToHtml(Color color)

Converts a Color object to its HTML string representation.

Color color = Color.FromArgb(255, 87, 51);
string htmlColor = color.ToHtml(); // Returns "#FF5733"

Color semiTransparent = Color.FromArgb(128, 255, 87, 51);
string htmlWithAlpha = semiTransparent.ToHtml(); // Returns "#FF573380"

Brushes

Abstract brush classes for painting operations.

SolidBrush

A brush that paints with a single, solid color.

using Ecng.Drawing;
using System.Drawing;

// Create a solid red brush
var redBrush = new SolidBrush(Color.Red);
Color brushColor = redBrush.Color;

// Create from HTML color
var blueBrush = new SolidBrush("#0000FF".ToColor());
LinearGradientBrush

A brush that paints with a gradient between multiple colors.

using Ecng.Drawing;
using System.Drawing;

// Method 1: Using color array and rectangle
var colors = new[] { Color.Red, Color.Yellow, Color.Blue };
var rectangle = new Rectangle(0, 0, 100, 100);
var gradientBrush = new LinearGradientBrush(colors, rectangle);

// Method 2: Using two points and two colors
var point1 = new Point(0, 0);
var point2 = new Point(100, 100);
var twoColorGradient = new LinearGradientBrush(
    point1,
    point2,
    Color.White,
    Color.Black
);

// Access gradient properties
Color[] gradientColors = gradientBrush.LinearColors;
Rectangle bounds = gradientBrush.Rectangle;

Layout and Alignment

Thickness

Represents the thickness of a frame around a rectangle (padding or margin).

using Ecng.Drawing;

// Create uniform thickness
var uniformThickness = new Thickness(10, 10, 10, 10);

// Create non-uniform thickness (left, top, right, bottom)
var customThickness = new Thickness(5, 10, 5, 20);

// Access individual values
double leftPadding = customThickness.Left;     // 5
double topPadding = customThickness.Top;       // 10
double rightPadding = customThickness.Right;   // 5
double bottomPadding = customThickness.Bottom; // 20

// Modify thickness values
customThickness.Left = 15;
customThickness.Top = 15;
HorizontalAlignment

Defines horizontal positioning within a layout container.

using Ecng.Drawing;

// Available alignment options
HorizontalAlignment leftAlign = HorizontalAlignment.Left;
HorizontalAlignment centerAlign = HorizontalAlignment.Center;
HorizontalAlignment rightAlign = HorizontalAlignment.Right;
HorizontalAlignment stretchAlign = HorizontalAlignment.Stretch;

// Usage in UI layout
void PositionElement(HorizontalAlignment alignment)
{
    switch (alignment)
    {
        case HorizontalAlignment.Left:
            // Align element to left
            break;
        case HorizontalAlignment.Center:
            // Center element
            break;
        case HorizontalAlignment.Right:
            // Align element to right
            break;
        case HorizontalAlignment.Stretch:
            // Stretch element to fill width
            break;
    }
}
VerticalAlignment

Defines vertical positioning within a layout container.

using Ecng.Drawing;

// Available alignment options
VerticalAlignment topAlign = VerticalAlignment.Top;
VerticalAlignment centerAlign = VerticalAlignment.Center;
VerticalAlignment bottomAlign = VerticalAlignment.Bottom;
VerticalAlignment stretchAlign = VerticalAlignment.Stretch;

// Usage in UI layout
void PositionElement(VerticalAlignment alignment)
{
    switch (alignment)
    {
        case VerticalAlignment.Top:
            // Align element to top
            break;
        case VerticalAlignment.Center:
            // Center element vertically
            break;
        case VerticalAlignment.Bottom:
            // Align element to bottom
            break;
        case VerticalAlignment.Stretch:
            // Stretch element to fill height
            break;
    }
}

Drawing Styles

The DrawStyles enum defines various visualization and charting styles.

using Ecng.Drawing;

// Available drawing styles
DrawStyles lineStyle = DrawStyles.Line;              // Standard line
DrawStyles noGapLine = DrawStyles.NoGapLine;         // Line without gaps
DrawStyles stepLine = DrawStyles.StepLine;           // Stepped line
DrawStyles band = DrawStyles.Band;                   // Band/area between values
DrawStyles bandOneValue = DrawStyles.BandOneValue;   // Single-value range
DrawStyles dot = DrawStyles.Dot;                     // Dot/scatter plot
DrawStyles histogram = DrawStyles.Histogram;         // Histogram bars
DrawStyles bubble = DrawStyles.Bubble;               // Bubble chart
DrawStyles stackedBar = DrawStyles.StackedBar;       // Stacked bar chart
DrawStyles dashedLine = DrawStyles.DashedLine;       // Dashed line
DrawStyles area = DrawStyles.Area;                   // Filled area

// Usage example
void ApplyChartStyle(DrawStyles style)
{
    switch (style)
    {
        case DrawStyles.Line:
            // Render as continuous line
            break;
        case DrawStyles.Histogram:
            // Render as vertical bars
            break;
        case DrawStyles.Bubble:
            // Render as sized bubbles
            break;
        // ... handle other styles
    }
}

Usage Examples

Example 1: Color Manipulation and Conversion

using Ecng.Drawing;
using System.Drawing;

public class ColorExample
{
    public void DemonstrateColorConversion()
    {
        // Convert HTML colors
        Color red = "#FF0000".ToColor();
        Color blue = "#00F".ToColor();
        Color custom = "#A52A2A".ToColor();

        // Convert to HTML
        string redHtml = red.ToHtml();        // "#FF0000"
        string blueHtml = blue.ToHtml();      // "#0000FF"

        // Work with ARGB integers
        int argbValue = -65536; // Red
        Color fromArgb = argbValue.ToColor();

        // Handle transparency
        Color transparent = Color.FromArgb(128, 255, 0, 0);
        string htmlWithAlpha = transparent.ToHtml(); // "#FF000080"
    }
}

Example 2: Creating Custom Brushes

using Ecng.Drawing;
using System.Drawing;

public class BrushExample
{
    public Brush CreateBackgroundBrush(bool useGradient)
    {
        if (useGradient)
        {
            // Create a gradient from top to bottom
            var topColor = "#2C3E50".ToColor();
            var bottomColor = "#4CA1AF".ToColor();

            return new LinearGradientBrush(
                new Point(0, 0),
                new Point(0, 100),
                topColor,
                bottomColor
            );
        }
        else
        {
            // Create a solid brush
            return new SolidBrush("#34495E".ToColor());
        }
    }

    public Brush CreateMultiColorGradient()
    {
        // Create a rainbow gradient
        var colors = new[]
        {
            Color.Red,
            Color.Orange,
            Color.Yellow,
            Color.Green,
            Color.Blue,
            Color.Purple
        };

        var bounds = new Rectangle(0, 0, 200, 50);
        return new LinearGradientBrush(colors, bounds);
    }
}

Example 3: UI Layout with Alignment and Thickness

using Ecng.Drawing;

public class LayoutExample
{
    public class ElementLayout
    {
        public Thickness Margin { get; set; }
        public Thickness Padding { get; set; }
        public HorizontalAlignment HorizontalAlignment { get; set; }
        public VerticalAlignment VerticalAlignment { get; set; }
    }

    public ElementLayout CreateButtonLayout()
    {
        return new ElementLayout
        {
            Margin = new Thickness(10, 5, 10, 5),
            Padding = new Thickness(15, 8, 15, 8),
            HorizontalAlignment = HorizontalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Center
        };
    }

    public ElementLayout CreatePanelLayout()
    {
        return new ElementLayout
        {
            Margin = new Thickness(0, 0, 0, 0),
            Padding = new Thickness(20, 20, 20, 20),
            HorizontalAlignment = HorizontalAlignment.Stretch,
            VerticalAlignment = VerticalAlignment.Stretch
        };
    }
}

Example 4: Chart Rendering with Drawing Styles

using Ecng.Drawing;
using System.Drawing;

public class ChartExample
{
    public class ChartSeries
    {
        public string Name { get; set; }
        public DrawStyles Style { get; set; }
        public Brush Brush { get; set; }
        public double[] Data { get; set; }
    }

    public ChartSeries CreatePriceSeries()
    {
        return new ChartSeries
        {
            Name = "Price",
            Style = DrawStyles.Line,
            Brush = new SolidBrush("#3498DB".ToColor()),
            Data = new[] { 100.0, 102.5, 101.8, 103.2, 105.0 }
        };
    }

    public ChartSeries CreateVolumeSeries()
    {
        return new ChartSeries
        {
            Name = "Volume",
            Style = DrawStyles.Histogram,
            Brush = new SolidBrush("#95A5A6".ToColor()),
            Data = new[] { 1000000, 1200000, 950000, 1100000, 1300000 }
        };
    }

    public ChartSeries CreateTrendBand()
    {
        var colors = new[]
        {
            Color.FromArgb(50, 52, 152, 219),  // Transparent blue
            Color.FromArgb(50, 46, 204, 113)   // Transparent green
        };

        return new ChartSeries
        {
            Name = "Trend Band",
            Style = DrawStyles.Band,
            Brush = new LinearGradientBrush(
                colors,
                new Rectangle(0, 0, 100, 100)
            ),
            Data = new[] { 95.0, 97.5, 98.0, 99.5, 100.0 }
        };
    }
}

Example 5: Complete UI Component

using Ecng.Drawing;
using System.Drawing;

public class CustomPanel
{
    public Thickness Margin { get; set; }
    public Thickness Padding { get; set; }
    public HorizontalAlignment HorizontalAlignment { get; set; }
    public VerticalAlignment VerticalAlignment { get; set; }
    public Brush Background { get; set; }

    public static CustomPanel CreateStyledPanel()
    {
        // Create a gradient background
        var gradient = new LinearGradientBrush(
            new Point(0, 0),
            new Point(0, 200),
            "#ECF0F1".ToColor(),
            "#BDC3C7".ToColor()
        );

        return new CustomPanel
        {
            Margin = new Thickness(10, 10, 10, 10),
            Padding = new Thickness(20, 20, 20, 20),
            HorizontalAlignment = HorizontalAlignment.Stretch,
            VerticalAlignment = VerticalAlignment.Top,
            Background = gradient
        };
    }

    public static CustomPanel CreateAccentPanel()
    {
        return new CustomPanel
        {
            Margin = new Thickness(5, 5, 5, 5),
            Padding = new Thickness(15, 10, 15, 10),
            HorizontalAlignment = HorizontalAlignment.Left,
            VerticalAlignment = VerticalAlignment.Center,
            Background = new SolidBrush("#E74C3C".ToColor())
        };
    }
}

Target Frameworks

This library supports the following target frameworks:

  • .NET Standard 2.0: Maximum compatibility with .NET Framework, .NET Core, and Xamarin
  • .NET 6.0: Modern .NET with long-term support
  • .NET 10.0: Latest .NET features and performance improvements

Platform-Specific Notes

.NET Standard 2.0

On .NET Standard 2.0, the library includes custom implementations for HTML color conversion that handle:

  • Standard hex color formats (#RGB, #RRGGBB)
  • Transparency in hex format (#RRGGBBAA)
  • Special case for LightGrey vs LightGray naming differences

.NET 6.0+

On .NET 6.0 and later, the library leverages the built-in ColorTranslator class for improved performance and compatibility.

Best Practices

  1. Color Conversions: Use the extension methods for consistent color handling across different representations
  2. Brush Lifetime: Create brushes as needed and reuse them when possible to avoid unnecessary allocations
  3. Layout Values: Use Thickness for consistent spacing and padding throughout your UI
  4. Drawing Styles: Choose appropriate styles for your data visualization needs
  5. Alignment: Combine HorizontalAlignment and VerticalAlignment for precise element positioning

License

Part of the StockSharp/Ecng library collection.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Ecng.Drawing:

Package Downloads
StockSharp.BusinessEntities

Trading entities (security, trade etc.). More info on web site https://stocksharp.com/store/

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Ecng.Drawing:

Repository Stars
StockSharp/StockSharp
Algorithmic trading and quantitative trading open source platform to develop trading robots (stock markets, forex, crypto, bitcoins, and options).
Version Downloads Last Updated
1.0.167 187 2/1/2026
1.0.166 152 1/22/2026
1.0.165 183 1/19/2026
1.0.164 100 1/18/2026
1.0.163 87 1/18/2026
1.0.162 159 1/14/2026
1.0.161 95 1/13/2026
1.0.160 96 1/13/2026
1.0.159 201 1/9/2026
1.0.158 199 1/4/2026
1.0.157 136 12/30/2025
1.0.156 125 12/29/2025
1.0.155 122 12/26/2025
1.0.154 110 12/26/2025
1.0.153 117 12/26/2025
1.0.152 131 12/26/2025
1.0.151 203 12/25/2025
1.0.150 214 12/25/2025
1.0.149 197 12/22/2025
1.0.148 180 12/21/2025
1.0.147 261 12/19/2025
1.0.146 263 12/19/2025
1.0.145 356 12/17/2025
1.0.144 336 12/15/2025
1.0.143 195 12/12/2025
1.0.142 149 12/12/2025
1.0.141 286 11/29/2025
1.0.140 157 11/28/2025
1.0.139 161 11/28/2025
1.0.138 213 11/27/2025
1.0.137 304 11/24/2025
1.0.136 220 11/24/2025
1.0.135 223 11/23/2025
1.0.134 277 11/22/2025
1.0.133 519 11/20/2025
1.0.132 477 11/18/2025
1.0.131 428 11/18/2025
1.0.130 421 11/13/2025
1.0.129 304 11/10/2025
1.0.128 1,170 11/1/2025
1.0.127 285 10/28/2025
1.0.126 272 10/27/2025
1.0.125 242 10/27/2025
1.0.124 153 10/25/2025
1.0.123 1,217 10/3/2025
1.0.122 450 9/25/2025
1.0.121 4,075 8/30/2025
1.0.120 356 8/19/2025
1.0.119 3,041 7/13/2025
1.0.118 232 7/13/2025
1.0.117 231 7/12/2025
1.0.116 620 7/8/2025
1.0.115 2,172 6/16/2025
1.0.114 389 6/9/2025
1.0.113 324 6/8/2025
1.0.112 756 5/21/2025
1.0.111 245 5/17/2025
1.0.110 819 5/12/2025
1.0.109 330 5/12/2025
1.0.108 389 4/17/2025
1.0.107 1,759 3/20/2025
1.0.106 268 3/19/2025
1.0.105 1,270 2/26/2025
1.0.104 223 2/26/2025
1.0.103 1,596 2/5/2025
1.0.102 307 1/21/2025
1.0.101 274 1/14/2025
1.0.100 238 1/12/2025
1.0.99 258 1/10/2025
1.0.98 2,838 11/18/2024
1.0.97 704 11/7/2024
1.0.96 343 10/19/2024
1.0.95 1,811 10/5/2024
1.0.94 1,529 9/18/2024
1.0.93 229 9/17/2024
1.0.92 671 9/14/2024
1.0.91 736 9/1/2024
1.0.90 3,176 6/12/2024
1.0.89 558 5/28/2024
1.0.88 1,191 5/4/2024
1.0.87 838 4/14/2024
1.0.86 843 3/28/2024
1.0.85 318 3/17/2024
1.0.84 930 2/23/2024
1.0.83 263 2/23/2024
1.0.82 704 2/18/2024
1.0.81 280 2/16/2024
1.0.80 580 2/13/2024
1.0.79 504 2/8/2024
1.0.78 497 2/4/2024
1.0.77 526 1/23/2024
1.0.76 640 1/12/2024
1.0.75 743 1/2/2024
1.0.74 284 12/29/2023
1.0.73 1,716 11/12/2023
1.0.72 212 11/10/2023
1.0.71 202 11/10/2023
1.0.70 213 11/9/2023
1.0.69 245 11/3/2023
1.0.68 251 11/1/2023
1.0.67 213 11/1/2023
1.0.66 1,729 9/8/2023
1.0.65 262 9/8/2023
1.0.64 308 9/3/2023
1.0.63 364 8/21/2023
1.0.62 277 8/14/2023
1.0.61 298 8/11/2023
1.0.60 255 8/10/2023
1.0.59 1,779 6/29/2023
1.0.58 870 5/27/2023
1.0.57 345 5/19/2023
1.0.56 1,100 5/8/2023
1.0.55 392 4/21/2023
1.0.54 1,943 4/3/2023
1.0.53 474 3/13/2023
1.0.52 1,185 3/6/2023
1.0.51 447 2/26/2023
1.0.50 1,657 2/9/2023
1.0.49 772 2/7/2023
1.0.48 447 2/4/2023
1.0.47 875 2/2/2023
1.0.46 815 1/30/2023
1.0.45 503 1/18/2023
1.0.44 1,848 12/30/2022
1.0.43 497 12/23/2022
1.0.42 1,190 12/12/2022
1.0.41 1,001 12/4/2022
1.0.40 477 12/4/2022
1.0.39 526 11/30/2022
1.0.38 486 11/28/2022
1.0.37 541 11/18/2022
1.0.36 1,475 11/11/2022
1.0.35 512 11/11/2022
1.0.34 525 11/10/2022
1.0.33 559 11/6/2022
1.0.32 532 11/5/2022
1.0.31 514 11/4/2022
1.0.30 1,215 11/1/2022
1.0.29 1,416 10/16/2022
1.0.28 711 9/10/2022
1.0.27 2,198 9/8/2022
1.0.26 607 9/8/2022
1.0.25 636 9/8/2022
1.0.24 616 9/4/2022
1.0.23 2,717 8/24/2022
1.0.22 724 8/8/2022
1.0.21 1,294 7/26/2022
1.0.20 605 7/26/2022
1.0.19 2,301 7/19/2022
1.0.18 1,769 7/18/2022
1.0.17 1,730 7/8/2022
1.0.16 1,362 6/18/2022
1.0.15 709 6/6/2022
1.0.14 4,075 4/30/2022
1.0.13 659 4/20/2022
1.0.12 691 4/10/2022
1.0.11 687 4/7/2022
1.0.10 645 4/7/2022
1.0.9 699 4/2/2022
1.0.8 2,207 3/29/2022
1.0.7 667 3/27/2022
1.0.6 7,663 2/20/2022
1.0.5 3,817 1/24/2022
1.0.4 535 12/29/2021
1.0.3 550 12/20/2021
1.0.2 506 12/13/2021
1.0.1 815 12/6/2021
1.0.0 512 12/2/2021