예제 #1
0
    public static Color ModeColor(QuickImage Source)
    {
        List <Color> Colors     = new List <Color>();
        List <int>   ColorCount = new List <int>();

        for (int x = 0; x < Source.Source.Width; x++)
        {
            for (int y = 0; y < Source.Source.Height; y++)
            {
                Color Pixel = Source.GetPixel(x, y);

                if (!Colors.Contains(Pixel))
                {
                    Colors.Add(Pixel);
                    ColorCount.Add(1);
                }
                else
                {
                    ColorCount[Colors.IndexOf(Pixel)]++;
                }
            }
        }

        return(Colors[Utility.Utility.Greatest(ColorCount)]);
    }
예제 #2
0
    /*
     * public static void GenerateFontImages(string FontName, int Size)
     * {
     *  SaveFontLetters(FontName, Size, CreateFontLetters(FontName, Size));
     *  CloseCropDirectory(FontName + "_" + Size.ToString());
     * }*/

    public static Color AverageColor(QuickImage Source)
    {
        int R     = 0;
        int G     = 0;
        int B     = 0;
        int Count = Source.Source.Width * Source.Source.Height;

        for (int x = 0; x < Source.Source.Width; x++)
        {
            for (int y = 0; y < Source.Source.Height; y++)
            {
                Color Pixel = Source.GetPixel(x, y);
                R += Pixel.R;
                G += Pixel.G;
                B += Pixel.B;
            }
        }

        return(Color.FromArgb(R / Count, G / Count, B / Count));
    }
예제 #3
0
    public List <Shape> FindAllDots(QuickImage Source, Color Background)
    {
        List <Shape> Dots = new List <Shape>();

        float W1 = 1.0f / Source.Source.Width;
        float H1 = 1.0f / Source.Source.Height;

        for (float x = 0.0f; x < Source.Source.Width; x++)
        {
            for (float y = 0.0f; y < Source.Source.Height; y++)
            {
                if (!ImageUtility.RoughColorMatch(Background, Source.GetPixel((int)x, (int)y), 2))
                {
                    Dots.Add(new Shape(x / Source.Source.Width, y / Source.Source.Height));
                }
            }
        }

        Console.WriteLine("Done");

        Console.WriteLine("Finding neighbors.");

        //Calculate all neighbors
        for (int i = 0; i < Dots.Count; i++)
        {
            if (i % Utility.Utility.LowerBound((Dots.Count / 40), 1) == 0)
            {
                Console.WriteLine("Processing: {0}/{1}", i, Dots.Count);
            }

            Shape Find = Dots[i];
            bool  LX = false, GX = false;
            bool  LY = false, GY = false;

            if (Find.X > 0)
            {
                LX = true;
            }
            if (Find.X < (Source.Source.Width - 1))
            {
                GX = true;
            }
            if (Find.Y > 0)
            {
                LY = true;
            }
            if (Find.Y < (Source.Source.Height - 1))
            {
                GY = true;
            }

            List <Shape> GXC = Dots.Where(N => N.Equals(new Shape(Find.X + W1, Find.Y))).ToList();

            if (LX && Dots.Where(N => N.Equals(new Shape(Find.X - W1, Find.Y))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X - W1, Find.Y))));
            }
            if (GX && Dots.Where(N => N.Equals(new Shape(Find.X + W1, Find.Y))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X + W1, Find.Y))));
            }
            if (LY && Dots.Where(N => N.Equals(new Shape(Find.X, Find.Y - H1))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X, Find.Y - H1))));
            }
            if (GY && Dots.Where(N => N.Equals(new Shape(Find.X, Find.Y + H1))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X, Find.Y + H1))));
            }
            if (LX && LY && Dots.Where(N => N.Equals(new Shape(Find.X - W1, Find.Y - H1))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X - W1, (Find.Y - H1)))));
            }
            if (LX && GY && Dots.Where(N => N.Equals(new Shape(Find.X - W1, Find.Y + H1))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X - W1, (Find.Y + H1)))));
            }
            if (GX && LY && Dots.Where(N => N.Equals(new Shape(Find.X + W1, Find.Y - H1))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X + W1, (Find.Y - H1)))));
            }
            if (GX && GY && Dots.Where(N => N.Equals(new Shape(Find.X + W1, Find.Y + H1))).Count() > 0)
            {
                Find.Neighbors.Add(Dots.First(D => D.Equals(new Shape(Find.X + W1, (Find.Y + H1)))));
            }
        }

        Console.WriteLine("Done");

        return(Dots);
    }