예제 #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 Size ExtractTextSize(Bitmap Source)
    {
        Size Result = new Size();

        QuickImage Check = new QuickImage(Source);

        Rectangle AreaHeight = Check.HeightBoundLine(Color.White);
        Rectangle AreaWidth  = Check.WidthBoundLine(Color.White);

        Result.Width  = AreaWidth.Width - 1;
        Result.Height = AreaHeight.Height - 1;

        return(Result);
    }
예제 #3
0
    public static Image CloseCrop(Image Source, string Name)
    {
        QuickImage Check = new QuickImage(Source);

        Rectangle AreaHeight = Check.HeightBounds(Color.White);
        Rectangle AreaWidth  = Check.WidthBounds(Color.White);

        Rectangle Area = new Rectangle(-1, -1, -1, -1);

        Area.X = AreaWidth.X;
        Area.Y = AreaHeight.Y;

        Area.Width  = AreaWidth.Width;
        Area.Height = AreaHeight.Height;

        return((Image)Check.Crop(Area).Save(Name));
    }
예제 #4
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));
    }
예제 #5
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);
    }
예제 #6
0
    public void Create(QuickImage Source)
    {
        Console.WriteLine("Template processing starting.");

        Console.WriteLine("Getting image size.");
        Width  = Source.Source.Width;
        Height = Source.Source.Height;
        Console.WriteLine("Done. Image is {0}x{1}.", Width, Height);

        Color Background = new Color();

        Console.WriteLine("Finding the mode color.");
        Background = ImageUtility.ModeColor(Source);
        Console.WriteLine("Done. Mode color is " + Background.ToString() + ".");

        Console.WriteLine("Creating list of all dots.");
        List <Shape> Dots = FindAllDots(Source, Background);

        Console.WriteLine("Finding all dots that are on their own.");
        Dots = FilterDots(Dots);
        Console.WriteLine("Done. {0} found.", Components.Count);

        List <Shape> LineCandidates = new List <Shape>();

        Console.WriteLine("Finding all possible lines");
        //Find everything that could be a line
        int i = 0;

        while (i < Dots.Count)
        {
            if (Dots[i].Neighbors.Count == 2)
            {
                LineCandidates.Add(Dots[i]);
                Dots.RemoveAt(i);
            }
            else
            {
                i++;
            }
        }

        Console.WriteLine("Done. {0} found.", LineCandidates.Count);

        Console.WriteLine("Filtering line candidates");
        //Filter the lines
        LineCandidates = FilterLineCandidates(LineCandidates);
        Console.WriteLine("Done. {0} left.", LineCandidates.Count);

        int OldCount = Components.Count;

        //Create the actual lines
        Console.WriteLine("Creating lines.");
        Components.AddRange(MakeLines(LineCandidates));

        int Created = Components.Count - OldCount;

        Console.WriteLine("Done. {0} made.", Created);

        Console.WriteLine("Adding {0} dots to the component list.", Dots.Count);
        //Add the rest of the leftover dots as plain dots.
        Components.AddRange(Dots);

        Console.WriteLine("Done.");

        Console.WriteLine("Template created. {0} components.", Components.Count);
    }
예제 #7
0
 public Template(QuickImage Source)
 {
     Create(Source);
 }