Example #1
0
    public Point GetLine(int X, int Y, int Length, int Direction, int TravelDirection, Color Find)
    {
        //0 is top down. This means we run through the x's at each height.
        Order GetX = (D, PX, PY) => (D == 0) ? PY : PX;
        Order GetY = (D, PX, PY) => (D == 0) ? PX : PY;

        int Width  = (TravelDirection < 0) ? 0 : Source.Width;
        int Height = (TravelDirection < 0) ? 0 : Source.Height;

        for (int x = GetX(Direction, X, Y); x != GetX(Direction, Width, Height); x += TravelDirection)
        {
            for (int y = GetY(Direction, X, Y); y != GetY(Direction, Width, Height); y += TravelDirection)
            {
                bool Match = true;

                for (int i = y; i != (Length * TravelDirection + y); i += TravelDirection)
                {
                    if (!ImageUtility.ColorMatch(GetPixel(GetX(Direction, x, i), GetY(Direction, x, i)), Find))
                    {
                        Match = false;
                    }
                }

                if (Match)
                {
                    return(new Point(GetX(Direction, x, y), GetY(Direction, x, y)));
                }
            }
        }

        return(Point.Empty);
    }
Example #2
0
    public Bitmap ColorAllPixels(Color Replace, params Color[] Ignore)
    {
        for (int x = 0; x < Source.Width; x++)
        {
            for (int y = 0; y < Source.Height; y++)
            {
                bool Match = false;
                foreach (Color IgnoreColor in Ignore)
                {
                    if (ImageUtility.ColorMatch(GetPixel(x, y), IgnoreColor))
                    {
                        Match = true;
                        break;
                    }
                }

                if (!Match)
                {
                    SetPixel(x, y, Replace);
                }
            }
        }

        return(Offload());
    }
Example #3
0
    public Rectangle HeightBoundLine(Color Blank)
    {
        Rectangle Result = new Rectangle(-1, -1, -1, -1);

        Point UpperBounds = GetColor(0, 0, 0, 1, Color.Black);

        //Find the upper bounds
        for (int y = 0; y < Source.Height; y++)
        {
            if ((Result.X == -1) || (Result.Y == -1))
            {
                for (int x = 0; x < Source.Width; x++)
                {
                    if (!ImageUtility.ColorMatch(GetPixel(x, y), Blank))
                    {
                        Result.X = x;
                        Result.Y = y;

                        break;
                    }
                }
            }
            else
            {
                break;
            }
        }

        Point LowerBounds = GetLine(Result.X, Result.Y, Source.Height, 0, 1, Color.White);

        //Find the lower bounds
        for (int y = Result.Y; y < Source.Height; y++)
        {
            if ((Result.Width == -1) || (Result.Height == -1))
            {
                bool Line = true;

                for (int x = Result.X; x < Source.Width; x++)
                {
                    if (!ImageUtility.ColorMatch(GetPixel(x, y), Blank))
                    {
                        Line = false;
                    }
                }

                if (Line)
                {
                    Result.Height = y - Result.Y + 1;
                    break;
                }
            }
            else
            {
                break;
            }
        }

        return(Result);
    }
Example #4
0
    public Rectangle WidthBoundLine(Color Blank)
    {
        Rectangle Result = new Rectangle(-1, -1, -1, -1);

        //Find the left bounds
        for (int x = 0; x < Source.Width; x++)
        {
            if ((Result.X == -1) || (Result.Y == -1))
            {
                for (int y = 0; y < Source.Height; y++)
                {
                    if (!ImageUtility.ColorMatch(GetPixel(x, y), Blank))
                    {
                        Result.X = x;
                        Result.Y = y;

                        break;
                    }
                }
            }
            else
            {
                break;
            }
        }

        //Find the right bounds
        for (int x = Result.X; x < Source.Width; x++)
        {
            if ((Result.Width == -1) || (Result.Height == -1))
            {
                bool Line = true;

                for (int y = Result.Y; y < Source.Height; y++)
                {
                    if (!ImageUtility.ColorMatch(GetPixel(x, y), Blank))
                    {
                        Line = false;
                    }
                }

                if (Line)
                {
                    Result.Width = x - Result.X + 1;
                    break;
                }
            }
            else
            {
                break;
            }
        }

        return(Result);
    }