Ecng.Drawing 1.0.149

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ecng.Drawing --version 1.0.149
                    
NuGet\Install-Package Ecng.Drawing -Version 1.0.149
                    
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.149" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Drawing" Version="1.0.149" />
                    
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.149
                    
#r "nuget: Ecng.Drawing, 1.0.149"
                    
#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.149
                    
#: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.149
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Drawing&version=1.0.149
                    
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.159 89 1/9/2026
1.0.158 184 1/4/2026
1.0.157 123 12/30/2025
1.0.156 111 12/29/2025
1.0.155 113 12/26/2025
1.0.154 100 12/26/2025
1.0.153 104 12/26/2025
1.0.152 119 12/26/2025
1.0.151 191 12/25/2025
1.0.150 199 12/25/2025
1.0.149 188 12/22/2025
1.0.148 169 12/21/2025
1.0.147 252 12/19/2025
1.0.146 250 12/19/2025
1.0.145 339 12/17/2025
1.0.144 328 12/15/2025
1.0.143 179 12/12/2025
1.0.142 133 12/12/2025
1.0.141 274 11/29/2025
1.0.140 147 11/28/2025
1.0.139 149 11/28/2025
1.0.138 202 11/27/2025
1.0.137 293 11/24/2025
1.0.136 208 11/24/2025
1.0.135 211 11/23/2025
1.0.134 262 11/22/2025
1.0.133 505 11/20/2025
1.0.132 462 11/18/2025
1.0.131 414 11/18/2025
1.0.130 406 11/13/2025
1.0.129 290 11/10/2025
1.0.128 1,156 11/1/2025
1.0.127 262 10/28/2025
1.0.126 261 10/27/2025
1.0.125 225 10/27/2025
1.0.124 140 10/25/2025
1.0.123 1,203 10/3/2025
1.0.122 435 9/25/2025
1.0.121 3,929 8/30/2025
1.0.120 345 8/19/2025
1.0.119 3,013 7/13/2025
1.0.118 217 7/13/2025
1.0.117 219 7/12/2025
1.0.116 606 7/8/2025
1.0.115 2,158 6/16/2025
1.0.114 380 6/9/2025
1.0.113 312 6/8/2025
1.0.112 746 5/21/2025
1.0.111 236 5/17/2025
1.0.110 805 5/12/2025
1.0.109 315 5/12/2025
1.0.108 377 4/17/2025
1.0.107 1,745 3/20/2025
1.0.106 255 3/19/2025
1.0.105 1,258 2/26/2025
1.0.104 211 2/26/2025
1.0.103 1,580 2/5/2025
1.0.102 295 1/21/2025
1.0.101 257 1/14/2025
1.0.100 228 1/12/2025
1.0.99 246 1/10/2025
1.0.98 2,824 11/18/2024
1.0.97 691 11/7/2024
1.0.96 333 10/19/2024
1.0.95 1,796 10/5/2024
1.0.94 1,511 9/18/2024
1.0.93 213 9/17/2024
1.0.92 658 9/14/2024
1.0.91 721 9/1/2024
1.0.90 3,161 6/12/2024
1.0.89 546 5/28/2024
1.0.88 1,179 5/4/2024
1.0.87 824 4/14/2024
1.0.86 829 3/28/2024
1.0.85 306 3/17/2024
1.0.84 916 2/23/2024
1.0.83 250 2/23/2024
1.0.82 694 2/18/2024
1.0.81 270 2/16/2024
1.0.80 569 2/13/2024
1.0.79 494 2/8/2024
1.0.78 484 2/4/2024
1.0.77 513 1/23/2024
1.0.76 627 1/12/2024
1.0.75 734 1/2/2024
1.0.74 273 12/29/2023
1.0.73 1,712 11/12/2023
1.0.72 206 11/10/2023
1.0.71 191 11/10/2023
1.0.70 205 11/9/2023
1.0.69 239 11/3/2023
1.0.68 243 11/1/2023
1.0.67 203 11/1/2023
1.0.66 1,725 9/8/2023
1.0.65 259 9/8/2023
1.0.64 299 9/3/2023
1.0.63 354 8/21/2023
1.0.62 270 8/14/2023
1.0.61 291 8/11/2023
1.0.60 248 8/10/2023
1.0.59 1,774 6/29/2023
1.0.58 864 5/27/2023
1.0.57 340 5/19/2023
1.0.56 1,094 5/8/2023
1.0.55 386 4/21/2023
1.0.54 1,936 4/3/2023
1.0.53 470 3/13/2023
1.0.52 1,175 3/6/2023
1.0.51 439 2/26/2023
1.0.50 1,650 2/9/2023
1.0.49 763 2/7/2023
1.0.48 443 2/4/2023
1.0.47 867 2/2/2023
1.0.46 808 1/30/2023
1.0.45 498 1/18/2023
1.0.44 1,843 12/30/2022
1.0.43 492 12/23/2022
1.0.42 1,180 12/12/2022
1.0.41 996 12/4/2022
1.0.40 470 12/4/2022
1.0.39 520 11/30/2022
1.0.38 480 11/28/2022
1.0.37 532 11/18/2022
1.0.36 1,472 11/11/2022
1.0.35 507 11/11/2022
1.0.34 512 11/10/2022
1.0.33 549 11/6/2022
1.0.32 525 11/5/2022
1.0.31 508 11/4/2022
1.0.30 1,212 11/1/2022
1.0.29 1,411 10/16/2022
1.0.28 706 9/10/2022
1.0.27 2,193 9/8/2022
1.0.26 602 9/8/2022
1.0.25 631 9/8/2022
1.0.24 609 9/4/2022
1.0.23 2,713 8/24/2022
1.0.22 718 8/8/2022
1.0.21 1,290 7/26/2022
1.0.20 595 7/26/2022
1.0.19 2,295 7/19/2022
1.0.18 1,765 7/18/2022
1.0.17 1,724 7/8/2022
1.0.16 1,355 6/18/2022
1.0.15 705 6/6/2022
1.0.14 4,064 4/30/2022
1.0.13 653 4/20/2022
1.0.12 685 4/10/2022
1.0.11 681 4/7/2022
1.0.10 643 4/7/2022
1.0.9 693 4/2/2022
1.0.8 2,201 3/29/2022
1.0.7 660 3/27/2022
1.0.6 7,659 2/20/2022
1.0.5 3,812 1/24/2022
1.0.4 527 12/29/2021
1.0.3 546 12/20/2021
1.0.2 502 12/13/2021
1.0.1 807 12/6/2021
1.0.0 505 12/2/2021