Ecng.Drawing 1.0.155

dotnet add package Ecng.Drawing --version 1.0.155
                    
NuGet\Install-Package Ecng.Drawing -Version 1.0.155
                    
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.155" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Drawing" Version="1.0.155" />
                    
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.155
                    
#r "nuget: Ecng.Drawing, 1.0.155"
                    
#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.155
                    
#: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.155
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Drawing&version=1.0.155
                    
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.155 0 12/26/2025
1.0.154 0 12/26/2025
1.0.153 0 12/26/2025
1.0.152 26 12/26/2025
1.0.151 113 12/25/2025
1.0.150 123 12/25/2025
1.0.149 169 12/22/2025
1.0.148 158 12/21/2025
1.0.147 239 12/19/2025
1.0.146 232 12/19/2025
1.0.145 322 12/17/2025
1.0.144 315 12/15/2025
1.0.143 163 12/12/2025
1.0.142 119 12/12/2025
1.0.141 259 11/29/2025
1.0.140 133 11/28/2025
1.0.139 135 11/28/2025
1.0.138 189 11/27/2025
1.0.137 281 11/24/2025
1.0.136 193 11/24/2025
1.0.135 196 11/23/2025
1.0.134 249 11/22/2025
1.0.133 490 11/20/2025
1.0.132 448 11/18/2025
1.0.131 398 11/18/2025
1.0.130 390 11/13/2025
1.0.129 276 11/10/2025
1.0.128 1,142 11/1/2025
1.0.127 247 10/28/2025
1.0.126 246 10/27/2025
1.0.125 213 10/27/2025
1.0.124 124 10/25/2025
1.0.123 1,190 10/3/2025
1.0.122 421 9/25/2025
1.0.121 3,813 8/30/2025
1.0.120 334 8/19/2025
1.0.119 2,998 7/13/2025
1.0.118 207 7/13/2025
1.0.117 201 7/12/2025
1.0.116 595 7/8/2025
1.0.115 2,142 6/16/2025
1.0.114 369 6/9/2025
1.0.113 296 6/8/2025
1.0.112 733 5/21/2025
1.0.111 223 5/17/2025
1.0.110 795 5/12/2025
1.0.109 302 5/12/2025
1.0.108 362 4/17/2025
1.0.107 1,720 3/20/2025
1.0.106 241 3/19/2025
1.0.105 1,234 2/26/2025
1.0.104 197 2/26/2025
1.0.103 1,567 2/5/2025
1.0.102 282 1/21/2025
1.0.101 242 1/14/2025
1.0.100 215 1/12/2025
1.0.99 233 1/10/2025
1.0.98 2,807 11/18/2024
1.0.97 681 11/7/2024
1.0.96 316 10/19/2024
1.0.95 1,776 10/5/2024
1.0.94 1,493 9/18/2024
1.0.93 203 9/17/2024
1.0.92 642 9/14/2024
1.0.91 709 9/1/2024
1.0.90 3,147 6/12/2024
1.0.89 532 5/28/2024
1.0.88 1,167 5/4/2024
1.0.87 811 4/14/2024
1.0.86 818 3/28/2024
1.0.85 291 3/17/2024
1.0.84 909 2/23/2024
1.0.83 236 2/23/2024
1.0.82 680 2/18/2024
1.0.81 258 2/16/2024
1.0.80 554 2/13/2024
1.0.79 483 2/8/2024
1.0.78 470 2/4/2024
1.0.77 502 1/23/2024
1.0.76 615 1/12/2024
1.0.75 719 1/2/2024
1.0.74 262 12/29/2023
1.0.73 1,703 11/12/2023
1.0.72 199 11/10/2023
1.0.71 183 11/10/2023
1.0.70 197 11/9/2023
1.0.69 232 11/3/2023
1.0.68 237 11/1/2023
1.0.67 195 11/1/2023
1.0.66 1,720 9/8/2023
1.0.65 248 9/8/2023
1.0.64 292 9/3/2023
1.0.63 347 8/21/2023
1.0.62 264 8/14/2023
1.0.61 284 8/11/2023
1.0.60 242 8/10/2023
1.0.59 1,767 6/29/2023
1.0.58 858 5/27/2023
1.0.57 330 5/19/2023
1.0.56 1,088 5/8/2023
1.0.55 382 4/21/2023
1.0.54 1,928 4/3/2023
1.0.53 463 3/13/2023
1.0.52 1,167 3/6/2023
1.0.51 432 2/26/2023
1.0.50 1,642 2/9/2023
1.0.49 758 2/7/2023
1.0.48 440 2/4/2023
1.0.47 862 2/2/2023
1.0.46 801 1/30/2023
1.0.45 490 1/18/2023
1.0.44 1,835 12/30/2022
1.0.43 486 12/23/2022
1.0.42 1,178 12/12/2022
1.0.41 991 12/4/2022
1.0.40 464 12/4/2022
1.0.39 513 11/30/2022
1.0.38 471 11/28/2022
1.0.37 522 11/18/2022
1.0.36 1,465 11/11/2022
1.0.35 501 11/11/2022
1.0.34 504 11/10/2022
1.0.33 542 11/6/2022
1.0.32 516 11/5/2022
1.0.31 496 11/4/2022
1.0.30 1,206 11/1/2022
1.0.29 1,405 10/16/2022
1.0.28 695 9/10/2022
1.0.27 2,185 9/8/2022
1.0.26 595 9/8/2022
1.0.25 627 9/8/2022
1.0.24 603 9/4/2022
1.0.23 2,707 8/24/2022
1.0.22 711 8/8/2022
1.0.21 1,282 7/26/2022
1.0.20 590 7/26/2022
1.0.19 2,288 7/19/2022
1.0.18 1,756 7/18/2022
1.0.17 1,711 7/8/2022
1.0.16 1,351 6/18/2022
1.0.15 698 6/6/2022
1.0.14 4,057 4/30/2022
1.0.13 644 4/20/2022
1.0.12 676 4/10/2022
1.0.11 674 4/7/2022
1.0.10 639 4/7/2022
1.0.9 687 4/2/2022
1.0.8 2,196 3/29/2022
1.0.7 653 3/27/2022
1.0.6 7,655 2/20/2022
1.0.5 3,806 1/24/2022
1.0.4 521 12/29/2021
1.0.3 537 12/20/2021
1.0.2 498 12/13/2021
1.0.1 801 12/6/2021
1.0.0 498 12/2/2021