Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,25 @@ public void From32BitArgb_Should_Equal_Drawing(string colorCode)
Assert.Equal(drawingColor.B, ironColor.B);
}

[Theory]
[InlineData(255, 177, 177, 177, "#B1B1B1")]
[InlineData(255, 0, 0, 0, "#000000")]
[InlineData(255, 255, 0, 0, "#FF0000")]
[InlineData(255, 0, 255, 0, "#00FF00")]
[InlineData(255, 0, 0, 255, "#0000FF")]
[InlineData(255, 30, 129, 176, "#1E81B0")]
public void ToHtml_ShouldReturnCorrectHtmlString(int a, int r, int g, int b, string expectedHtml)
{
// Arrange
var color = new Color(a, r, g, b);

// Act
var actualHtml = color.ToHtmlCssColorCode();

// Assert
Assert.Equal(expectedHtml, actualHtml);
}

#if !NETFRAMEWORK
[FactWithAutomaticDisplayName]
public void Cast_Maui_from_Color()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ public void Dispose()
return;
this.Image.Dispose();
this.Image = null;
this.Binary = null;
this.disposed = true;
}

Expand Down
9 changes: 9 additions & 0 deletions IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,15 @@ public override int GetHashCode()
return 0;
}

/// <summary>
/// Translates the specified Color structure to an HTML string color representation.
/// </summary>
/// <returns>A string containing the hex representation of the color in the format #RRGGBB.</returns>
public string ToHtmlCssColorCode()
{
return $"#{this.R:X2}{this.G:X2}{this.B:X2}";
}

#region Private Method

private static InvalidOperationException NoConverterException(string color, Exception innerException)
Expand Down
8 changes: 2 additions & 6 deletions NuGet/IronSoftware.Drawing.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ Supports:

For general support and technical inquiries, please email us at: developers@ironsoftware.com</description>
<summary>IronSoftware.System.Drawing is an open-source solution for .NET developers to replace System.Drawing.Common with a universal and flexible library.</summary>
<releaseNotes>* AnyBitmap
- GetPixel(x, y) which is a new accessor method to get the Color of a pixel in an AnyBitmap
- Adds new constructor to AnyBitmap which creates a new AnyBitmap from an existing AnyBitmap, scaled to the a custom width and height
- Fixes a bug when saving an image without specifying ImageFormat
* Color
- [Hotfix] Fixes a bug when comparing Color with null</releaseNotes>
<releaseNotes>- Added a deconstructor for the AnyBitmap class to automatically dispose of objects, simplifying memory management.
- Added a new function call to the Color class: ToHtmlCssColorCode(). This translates the specified Color structure to an HTML string color representation.</releaseNotes>
<copyright>Copyright © Iron Software 2022-2023</copyright>
<tags>Images, Bitmap, SkiaSharp, SixLabors, BitMiracle, Maui, SVG, TIFF, TIF, GIF, JPEG, PNG, Color, Rectangle, Drawing, C#, VB.NET, ASPX, create, render, generate, standard, netstandard2.0, core, netcore</tags>
<repository type="git" url="https://github.com/iron-software/IronSoftware.Drawing.Common" commit="$commit$" />
Expand Down