public void Color_Types_To_Hex_Produce_Equal_OutPut() { Rgba32 color = new Rgba32(24, 48, 96, 192); RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); // 183060C0 Assert.Equal(color.ToHex(), colorVector.ToHex()); }
public void ColorNames() { foreach (string name in ReferencePalette.ColorNames.Keys) { Rgba32 expected = ReferencePalette.ColorNames[name]; Assert.Equal(expected, (Rgba32)Color.Parse(name)); Assert.Equal(expected, (Rgba32)Color.Parse(name.ToLowerInvariant())); Assert.Equal(expected, (Rgba32)Color.Parse(expected.ToHex())); } }
public string GenerateCaption(ColorSpace initColorSpace, float[] colors) { Rgba32 rgb = _colorSpacesManager.CreateRgba32(initColorSpace.Name, colors); var caption = new StringBuilder(); string hex = rgb.ToHex(); // Removes alpha from HEX string if (hex.Length > 6) { hex = hex[..6];
public string GetLink(Rgba32 color, int width, int height, string name) { return(_domain.SetQueryParams(new { width, height, color = color.ToHex(), caption = name })); }
private void SetImagePrimaryHexColor() { // Pseudocode in case ASP.NET Core decides to support System.Drawing //if (LargeImage != null) //{ // using (MemoryStream memoryStream = new MemoryStream(LargeImage)) // { // Bitmap bitmap = new Bitmap(memoryStream); // List<Color> colors = new List<Color>(bitmap.Size.Width * bitmap.Size.Height); // for (int x = 0; x < bitmap.Size.Width; x++) // { // for (int y = 0; y < bitmap.Size.Height; y++) // { // try // { // colors.Add(bitmap.GetPixel(x, y)); // } // catch { } // } // } // Color modeColor = colors.GroupBy(c => c).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key).First(); // ImagePrimaryHexColor = ColorTranslator.ToHtml(modeColor); // } //} if (LargeImage != null) { using (MemoryStream memoryStream = new MemoryStream(LargeImage)) using (Image <Rgba32> image = Image.Load <Rgba32>(memoryStream)) { List <Rgba32> pixels = new List <Rgba32>(2 * image.Height); for (int y = 0; y < image.Height; y++) { // Gathering from the left & right edges. pixels.Add(image[0, y]); pixels.Add(image[image.Width, y]); } Rgba32 modePixel = pixels .GroupBy(p => p) .OrderByDescending(grp => grp.Count()) .Select(grp => grp.Key) .First(); ImagePrimaryHexColor = $"#{modePixel.ToHex()}"; } } }
public void FromAndToHex() { Rgba32 color = Rgba32.FromHex("#AABBCCDD"); Assert.Equal(170, color.R); Assert.Equal(187, color.G); Assert.Equal(204, color.B); Assert.Equal(221, color.A); color.A = 170; color.B = 187; color.G = 204; color.R = 221; Assert.Equal("DDCCBBAA", color.ToHex()); color.R = 0; Assert.Equal("00CCBBAA", color.ToHex()); color.A = 255; Assert.Equal("00CCBBFF", color.ToHex()); }
public void TryColorNames() { foreach (string name in ReferencePalette.ColorNames.Keys) { Rgba32 expected = ReferencePalette.ColorNames[name]; Assert.True(Color.TryParse(name, out Color actual)); Assert.Equal(expected, (Rgba32)actual); Assert.True(Color.TryParse(name.ToLowerInvariant(), out actual)); Assert.Equal(expected, (Rgba32)actual); Assert.True(Color.TryParse(expected.ToHex(), out actual)); Assert.Equal(expected, (Rgba32)actual); } }
public void MultiplePointGradients <TPixel>( TestImageProvider <TPixel> provider, int startX, int startY, int endX, int endY, float[] stopPositions, int[] stopColorCodes) where TPixel : struct, IPixel <TPixel> { TPixel[] colors = { NamedColors <TPixel> .Black, NamedColors <TPixel> .Blue, NamedColors <TPixel> .Red, NamedColors <TPixel> .White, NamedColors <TPixel> .Lime }; var coloringVariant = new StringBuilder(); var colorStops = new ColorStop <TPixel> [stopPositions.Length]; for (int i = 0; i < stopPositions.Length; i++) { TPixel color = colors[stopColorCodes[i % colors.Length]]; float position = stopPositions[i]; colorStops[i] = new ColorStop <TPixel>(position, color); Rgba32 rgba = default; color.ToRgba32(ref rgba); coloringVariant.AppendFormat(CultureInfo.InvariantCulture, "{0}@{1};", rgba.ToHex(), position); } FormattableString variant = $"({startX},{startY})_TO_({endX},{endY})__[{coloringVariant}]"; provider.VerifyOperation( image => { var unicolorLinearGradientBrush = new LinearGradientBrush <TPixel>( new SixLabors.Primitives.Point(startX, startY), new SixLabors.Primitives.Point(endX, endY), GradientRepetitionMode.None, colorStops); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, variant, false, false); }
public void ArbitraryGradients <TPixel>( TestImageProvider <TPixel> provider, int startX, int startY, int endX, int endY, float[] stopPositions, int[] stopColorCodes) where TPixel : unmanaged, IPixel <TPixel> { Color[] colors = { Color.Navy, Color.LightGreen, Color.Yellow, Color.Red }; var coloringVariant = new StringBuilder(); var colorStops = new ColorStop[stopPositions.Length]; for (int i = 0; i < stopPositions.Length; i++) { Color color = colors[stopColorCodes[i % colors.Length]]; float position = stopPositions[i]; colorStops[i] = new ColorStop(position, color); Rgba32 rgba = color; coloringVariant.AppendFormat(CultureInfo.InvariantCulture, "{0}@{1};", rgba.ToHex(), position); } FormattableString variant = $"({startX},{startY})_TO_({endX},{endY})__[{coloringVariant}]"; provider.VerifyOperation( image => { var unicolorLinearGradientBrush = new LinearGradientBrush( new Point(startX, startY), new Point(endX, endY), GradientRepetitionMode.None, colorStops); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, variant, false, false); }
public static string ToRgbHex(this Rgba32 color) { var hex = color.ToHex(); return(hex.Substring(0, 6)); }