Skip to content

Strange bug while trying to get a hex color by histogram. #799

@Marko97IT

Description

@Marko97IT

How to reproduce the bug:

using (MagickImage Image = new MagickImage(ImageBlob))
{
    Dictionary<IMagickColor<ushort>, int> Histogram = Image.Histogram();
    IMagickColor<ushort> DominantColor = Histogram.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;
    Console.WriteLine(string.Format("#{0}{1}{2}", DominantColor.R.ToString("X2"), DominantColor.G.ToString("X2"), DominantColor.B.ToString("X2")));
}

The output will be #B9B9B2B27E7E while it should be #B9B27E.
Adding .Substring(2) after ToString("X2") solves the problem.

The same problem also occurs using:
Console.WriteLine("#" + DominantColor.ToShortString());

therefore I think the problem is on the Histogram method.

Magick.NET Q16 AnyCPU v7.22.2.2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions