mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Added a helper method to convert colors to their HEX-representation
This commit is contained in:
parent
f323f6206d
commit
54f7ec97d1
34
RGB.NET.Core/Helper/ConversionHelper.cs
Normal file
34
RGB.NET.Core/Helper/ConversionHelper.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
namespace RGB.NET.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains helper methods for converting things.
|
||||||
|
/// </summary>
|
||||||
|
public static class ConversionHelper
|
||||||
|
{
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
// Source: https://web.archive.org/web/20180224104425/https://stackoverflow.com/questions/623104/byte-to-hex-string/3974535
|
||||||
|
/// <summary>
|
||||||
|
/// Converts an array of bytes to a HEX-representation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bytes">The array of bytes.</param>
|
||||||
|
/// <returns>The HEX-representation of the provided bytes.</returns>
|
||||||
|
public static string ToHex(params byte[] bytes)
|
||||||
|
{
|
||||||
|
char[] c = new char[bytes.Length * 2];
|
||||||
|
|
||||||
|
for (int bx = 0, cx = 0; bx < bytes.Length; ++bx, ++cx)
|
||||||
|
{
|
||||||
|
byte b = ((byte)(bytes[bx] >> 4));
|
||||||
|
c[cx] = (char)(b > 9 ? b + 0x37 + 0x20 : b + 0x30);
|
||||||
|
|
||||||
|
b = ((byte)(bytes[bx] & 0x0F));
|
||||||
|
c[++cx] = (char)(b > 9 ? b + 0x37 + 0x20 : b + 0x30);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -327,6 +327,18 @@ namespace RGB.NET.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current color as a RGB-HEX-string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The RGB-HEX-string.</returns>
|
||||||
|
public string AsRGBHexString() => ConversionHelper.ToHex(R, G, B);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current color as a ARGB-HEX-string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The ARGB-HEX-string.</returns>
|
||||||
|
public string AsARGBHexString() => ConversionHelper.ToHex(A, R, G, B);
|
||||||
|
|
||||||
#region Deconstruction
|
#region Deconstruction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -64,6 +64,7 @@
|
|||||||
<Compile Include="Devices\Layout\LedImage.cs" />
|
<Compile Include="Devices\Layout\LedImage.cs" />
|
||||||
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
||||||
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
||||||
|
<Compile Include="Helper\ConversionHelper.cs" />
|
||||||
<Compile Include="Helper\CultureHelper.cs" />
|
<Compile Include="Helper\CultureHelper.cs" />
|
||||||
<Compile Include="Helper\PathHelper.cs" />
|
<Compile Include="Helper\PathHelper.cs" />
|
||||||
<Compile Include="Leds\LedId.cs" />
|
<Compile Include="Leds\LedId.cs" />
|
||||||
|
|||||||
@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Debug
|
|||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool RequiresInitialization => false;
|
public bool RequiresInitialization => true;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user