public List<CharacterInfo> GetMatchCharacter(List<ConnectedPixel> connectingPixels)
 {
     CharacterPixel characterPixel = new CharacterPixel();
       List<CharacterInfo> characterInfos = new List<CharacterInfo>();
       List<ConnectedPixel> connectedPixels = connectingPixels.FindAll((ConnectedPixel x) => (x.m_width > 18 ? false : x.m_height <= 18));
       foreach (CharacterInfo mCharacterInfo in characterPixel.m_characterInfo)
       {
     foreach (ConnectedPixel connectedPixel in connectedPixels.FindAll((ConnectedPixel x) => (x.m_width != mCharacterInfo.Width || x.m_height != mCharacterInfo.Height ? false : this.MatchPixel(x, mCharacterInfo))))
     {
       CharacterInfo characterInfo = new CharacterInfo()
       {
     m_color = connectedPixel.m_color,
     m_bgColor = connectedPixel.m_bgColor,
     m_fontWeight = mCharacterInfo.m_fontWeight,
     TopYCor = connectedPixel.m_topYCor,
     BottomYCor = connectedPixel.m_bottomYCor,
     LeftXCor = connectedPixel.m_leftXCor,
     RightXCor = connectedPixel.m_rightXCor,
     Width = (byte)connectedPixel.m_width,
     Height = (byte)connectedPixel.m_height,
     CharacterDirection = mCharacterInfo.CharacterDirection,
     Character = mCharacterInfo.Character
       };
       characterInfos.Add(characterInfo);
       connectingPixels.Remove(connectedPixel);
     }
       }
       return characterInfos;
 }
        public List <CharacterInfo> GetMatchCharacter(List <ConnectedPixel> connectingPixels)
        {
            CharacterPixel        characterPixel  = new CharacterPixel();
            List <CharacterInfo>  characterInfos  = new List <CharacterInfo>();
            List <ConnectedPixel> connectedPixels = connectingPixels.FindAll((ConnectedPixel x) => (x.m_width > 18 ? false : x.m_height <= 18));

            foreach (CharacterInfo mCharacterInfo in characterPixel.m_characterInfo)
            {
                foreach (ConnectedPixel connectedPixel in connectedPixels.FindAll((ConnectedPixel x) => (x.m_width != mCharacterInfo.Width || x.m_height != mCharacterInfo.Height ? false : this.MatchPixel(x, mCharacterInfo))))
                {
                    CharacterInfo characterInfo = new CharacterInfo()
                    {
                        m_color            = connectedPixel.m_color,
                        m_bgColor          = connectedPixel.m_bgColor,
                        m_fontWeight       = mCharacterInfo.m_fontWeight,
                        TopYCor            = connectedPixel.m_topYCor,
                        BottomYCor         = connectedPixel.m_bottomYCor,
                        LeftXCor           = connectedPixel.m_leftXCor,
                        RightXCor          = connectedPixel.m_rightXCor,
                        Width              = (byte)connectedPixel.m_width,
                        Height             = (byte)connectedPixel.m_height,
                        CharacterDirection = mCharacterInfo.CharacterDirection,
                        Character          = mCharacterInfo.Character
                    };
                    characterInfos.Add(characterInfo);
                    connectingPixels.Remove(connectedPixel);
                }
            }
            return(characterInfos);
        }
 public List<CharacterInfo> MatchJoinedCharacter(List<ConnectedPixel> connectingPixels)
 {
     List<CharacterInfo> characterInfos = new List<CharacterInfo>();
       CharacterPixel characterPixel = new CharacterPixel();
       foreach (ConnectedPixel connectedPixel in connectingPixels.FindAll((ConnectedPixel x) => (x.m_width <= 6 || x.m_height <= 3 || x.m_width > 25 ? false : x.m_height <= 25)))
       {
     short mLeftXCor = connectedPixel.m_leftXCor;
     short num = connectedPixel.m_leftXCor;
     short num1 = 4;
     while (mLeftXCor <= connectedPixel.m_rightXCor)
     {
       mLeftXCor = (short)(num + num1);
       if (mLeftXCor <= connectedPixel.m_rightXCor + 1)
       {
     List<PixelPoint> pixelPoints = new List<PixelPoint>();
     short num2 = 0;
     short num3 = 0;
     for (int i = 0; i < connectedPixel.m_height; i++)
     {
       bool mPixelCoordinate = true;
       short num4 = 0;
       for (int j = num; j < mLeftXCor; j++)
       {
         mPixelCoordinate = mPixelCoordinate & !connectedPixel.m_pixelCoordinate[j - connectedPixel.m_leftXCor, i];
         if (connectedPixel.m_pixelCoordinate[j - connectedPixel.m_leftXCor, i])
         {
           pixelPoints.Add(new PixelPoint(num4, num2));
         }
         num4 = (short)(num4 + 1);
       }
       if (mPixelCoordinate)
       {
         num3 = (short)(num3 + 1);
       }
       else
       {
         num2 = (short)(num2 + 1);
       }
     }
     pixelPoints.Sort((PixelPoint object1, PixelPoint object2) => object1.XCor.CompareTo(object2.XCor));
     PixelPoint item = pixelPoints[pixelPoints.Count - 1];
     short xCor = item.XCor;
     item = pixelPoints[0];
     short xCor1 = (short)(xCor - item.XCor + 1);
     pixelPoints.Sort((PixelPoint object1, PixelPoint object2) => object1.YCor.CompareTo(object2.YCor));
     item = pixelPoints[pixelPoints.Count - 1];
     short yCor = item.YCor;
     item = pixelPoints[0];
     short yCor1 = (short)(yCor - item.YCor + 1);
     bool[,] flagArray = new bool[xCor1, yCor1];
     foreach (PixelPoint pixelPoint in pixelPoints)
     {
       flagArray[pixelPoint.XCor, pixelPoint.YCor] = true;
     }
     ConnectedPixel connectedPixel1 = new ConnectedPixel()
     {
       m_width = xCor1,
       m_height = yCor1,
       m_pixelCoordinate = flagArray,
       m_color = connectedPixel.m_color
     };
     ConnectedPixel connectedPixel2 = connectedPixel1;
     int num5 = characterPixel.m_characterInfo.FindIndex((CharacterInfo x) => this.MatchPixel(connectedPixel2, x));
     if (num5 == -1)
     {
       num1 = (short)(num1 + 1);
     }
     else
     {
       CharacterInfo characterInfo = new CharacterInfo()
       {
         m_color = connectedPixel2.m_color,
         m_bgColor = connectedPixel.m_bgColor,
         Character = characterPixel.m_characterInfo[num5].Character,
         TopYCor = (short)(connectedPixel.m_topYCor + num3),
         LeftXCor = num,
         BottomYCor = (short)(connectedPixel.m_topYCor + num3 + characterPixel.m_characterInfo[num5].Height - 1),
         RightXCor = (short)(mLeftXCor - 1),
         CharacterDirection = characterPixel.m_characterInfo[num5].CharacterDirection,
         Width = characterPixel.m_characterInfo[num5].Width,
         Height = characterPixel.m_characterInfo[num5].Height
       };
       characterInfos.Add(characterInfo);
       num = mLeftXCor;
       num1 = 4;
     }
     if (num1 > 5)
     {
       break;
     }
       }
       else
       {
     break;
       }
     }
       }
       return characterInfos;
 }
 internal List<ConnectedPixel> GetConnectedPixel(Bitmap bitmap, Dictionary<short, List<PixelPoint>> dicPixelPointConncected)
 {
     byte[] numArray;
       int num;
       int num1;
       ImageLabeling.GetRgbArrayFromImage(bitmap, out numArray, out num, out num1);
       List<ConnectedPixel> connectedPixels = new List<ConnectedPixel>();
       short width = (short)(bitmap.Width * 3);
       CharacterPixel characterPixel = new CharacterPixel();
       CharacterInfo characterInfo = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Bold));
       CharacterInfo characterInfo1 = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Normal));
       characterPixel.m_characterInfo.RemoveAll((CharacterInfo x) => (x == characterInfo ? false : x != characterInfo1));
       foreach (KeyValuePair<short, List<PixelPoint>> keyValuePair in dicPixelPointConncected)
       {
     if (keyValuePair.Value.Count <= 4000)
     {
       keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.YCor.CompareTo(sObject2.YCor));
       PixelPoint pixelPoint = keyValuePair.Value.FirstOrDefault<PixelPoint>();
       int yCor = pixelPoint.YCor;
       pixelPoint = keyValuePair.Value.LastOrDefault<PixelPoint>();
       int yCor1 = pixelPoint.YCor;
       keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.XCor.CompareTo(sObject2.XCor));
       pixelPoint = keyValuePair.Value.FirstOrDefault<PixelPoint>();
       int xCor = pixelPoint.XCor;
       pixelPoint = keyValuePair.Value.LastOrDefault<PixelPoint>();
       int xCor1 = pixelPoint.XCor;
       pixelPoint = keyValuePair.Value.First<PixelPoint>();
       int yCor2 = pixelPoint.YCor * width; // was short why?
       pixelPoint = keyValuePair.Value.First<PixelPoint>();
       int xCor2 = yCor2 + pixelPoint.XCor * 3;
       pixelPoint = keyValuePair.Value.First<PixelPoint>();
       int num2 = xCor2 + pixelPoint.YCor * num1;
       short num3 = (short)(xCor1 - xCor + 1);
       short num4 = (short)(yCor1 - yCor + 1);
       ConnectedPixel connectedPixel = new ConnectedPixel()
       {
     m_pixelCoordinate = new bool[num3, num4]
       };
       PxColor pxColor = new PxColor()
       {
     R = numArray[num2 + 2],
     G = numArray[num2 + 1],
     B = numArray[num2]
       };
       connectedPixel.m_color = pxColor;
       connectedPixel.m_height = num4;
       connectedPixel.m_width = num3;
       connectedPixel.m_topYCor = (short)yCor;
       connectedPixel.m_bottomYCor = (short)yCor1;
       connectedPixel.m_leftXCor = (short)xCor;
       connectedPixel.m_rightXCor = (short)xCor1;
       ConnectedPixel connectedPixel1 = connectedPixel;
       ConnectedCoordinate.CheckSpecialSeperatedDotCharacter(connectedPixel1, connectedPixels, characterInfo, characterInfo1, keyValuePair);
       ConnectedCoordinate.GetbackgroundColor(connectedPixel1, ref numArray, width, num1);
       connectedPixels.Add(connectedPixel1);
     }
       }
       return connectedPixels;
 }
        public List <CharacterInfo> MatchJoinedCharacter(List <ConnectedPixel> connectingPixels)
        {
            List <CharacterInfo> characterInfos = new List <CharacterInfo>();
            CharacterPixel       characterPixel = new CharacterPixel();

            foreach (ConnectedPixel connectedPixel in connectingPixels.FindAll((ConnectedPixel x) => (x.m_width <= 6 || x.m_height <= 3 || x.m_width > 25 ? false : x.m_height <= 25)))
            {
                short mLeftXCor = connectedPixel.m_leftXCor;
                short num       = connectedPixel.m_leftXCor;
                short num1      = 4;
                while (mLeftXCor <= connectedPixel.m_rightXCor)
                {
                    mLeftXCor = (short)(num + num1);
                    if (mLeftXCor <= connectedPixel.m_rightXCor + 1)
                    {
                        List <PixelPoint> pixelPoints = new List <PixelPoint>();
                        short             num2        = 0;
                        short             num3        = 0;
                        for (int i = 0; i < connectedPixel.m_height; i++)
                        {
                            bool  mPixelCoordinate = true;
                            short num4             = 0;
                            for (int j = num; j < mLeftXCor; j++)
                            {
                                mPixelCoordinate = mPixelCoordinate & !connectedPixel.m_pixelCoordinate[j - connectedPixel.m_leftXCor, i];
                                if (connectedPixel.m_pixelCoordinate[j - connectedPixel.m_leftXCor, i])
                                {
                                    pixelPoints.Add(new PixelPoint(num4, num2));
                                }
                                num4 = (short)(num4 + 1);
                            }
                            if (mPixelCoordinate)
                            {
                                num3 = (short)(num3 + 1);
                            }
                            else
                            {
                                num2 = (short)(num2 + 1);
                            }
                        }
                        pixelPoints.Sort((PixelPoint object1, PixelPoint object2) => object1.XCor.CompareTo(object2.XCor));
                        PixelPoint item = pixelPoints[pixelPoints.Count - 1];
                        short      xCor = item.XCor;
                        item = pixelPoints[0];
                        short xCor1 = (short)(xCor - item.XCor + 1);
                        pixelPoints.Sort((PixelPoint object1, PixelPoint object2) => object1.YCor.CompareTo(object2.YCor));
                        item = pixelPoints[pixelPoints.Count - 1];
                        short yCor = item.YCor;
                        item = pixelPoints[0];
                        short yCor1 = (short)(yCor - item.YCor + 1);
                        bool[,] flagArray = new bool[xCor1, yCor1];
                        foreach (PixelPoint pixelPoint in pixelPoints)
                        {
                            flagArray[pixelPoint.XCor, pixelPoint.YCor] = true;
                        }
                        ConnectedPixel connectedPixel1 = new ConnectedPixel()
                        {
                            m_width           = xCor1,
                            m_height          = yCor1,
                            m_pixelCoordinate = flagArray,
                            m_color           = connectedPixel.m_color
                        };
                        ConnectedPixel connectedPixel2 = connectedPixel1;
                        int            num5            = characterPixel.m_characterInfo.FindIndex((CharacterInfo x) => this.MatchPixel(connectedPixel2, x));
                        if (num5 == -1)
                        {
                            num1 = (short)(num1 + 1);
                        }
                        else
                        {
                            CharacterInfo characterInfo = new CharacterInfo()
                            {
                                m_color            = connectedPixel2.m_color,
                                m_bgColor          = connectedPixel.m_bgColor,
                                Character          = characterPixel.m_characterInfo[num5].Character,
                                TopYCor            = (short)(connectedPixel.m_topYCor + num3),
                                LeftXCor           = num,
                                BottomYCor         = (short)(connectedPixel.m_topYCor + num3 + characterPixel.m_characterInfo[num5].Height - 1),
                                RightXCor          = (short)(mLeftXCor - 1),
                                CharacterDirection = characterPixel.m_characterInfo[num5].CharacterDirection,
                                Width  = characterPixel.m_characterInfo[num5].Width,
                                Height = characterPixel.m_characterInfo[num5].Height
                            };
                            characterInfos.Add(characterInfo);
                            num  = mLeftXCor;
                            num1 = 4;
                        }
                        if (num1 > 5)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(characterInfos);
        }
        internal List <ConnectedPixel> GetConnectedPixel(Bitmap bitmap, Dictionary <short, List <PixelPoint> > dicPixelPointConncected)
        {
            byte[] numArray;
            int    num;
            int    num1;

            ImageLabeling.GetRgbArrayFromImage(bitmap, out numArray, out num, out num1);
            List <ConnectedPixel> connectedPixels = new List <ConnectedPixel>();
            short          width          = (short)(bitmap.Width * 3);
            CharacterPixel characterPixel = new CharacterPixel();
            CharacterInfo  characterInfo  = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Bold));
            CharacterInfo  characterInfo1 = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Normal));

            characterPixel.m_characterInfo.RemoveAll((CharacterInfo x) => (x == characterInfo ? false : x != characterInfo1));
            foreach (KeyValuePair <short, List <PixelPoint> > keyValuePair in dicPixelPointConncected)
            {
                if (keyValuePair.Value.Count <= 4000)
                {
                    keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.YCor.CompareTo(sObject2.YCor));
                    PixelPoint pixelPoint = keyValuePair.Value.FirstOrDefault <PixelPoint>();
                    int        yCor       = pixelPoint.YCor;
                    pixelPoint = keyValuePair.Value.LastOrDefault <PixelPoint>();
                    int yCor1 = pixelPoint.YCor;
                    keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.XCor.CompareTo(sObject2.XCor));
                    pixelPoint = keyValuePair.Value.FirstOrDefault <PixelPoint>();
                    int xCor = pixelPoint.XCor;
                    pixelPoint = keyValuePair.Value.LastOrDefault <PixelPoint>();
                    int xCor1 = pixelPoint.XCor;
                    pixelPoint = keyValuePair.Value.First <PixelPoint>();
                    int yCor2 = pixelPoint.YCor * width; // was short why?
                    pixelPoint = keyValuePair.Value.First <PixelPoint>();
                    int xCor2 = yCor2 + pixelPoint.XCor * 3;
                    pixelPoint = keyValuePair.Value.First <PixelPoint>();
                    int            num2           = xCor2 + pixelPoint.YCor * num1;
                    short          num3           = (short)(xCor1 - xCor + 1);
                    short          num4           = (short)(yCor1 - yCor + 1);
                    ConnectedPixel connectedPixel = new ConnectedPixel()
                    {
                        m_pixelCoordinate = new bool[num3, num4]
                    };
                    PxColor pxColor = new PxColor()
                    {
                        R = numArray[num2 + 2],
                        G = numArray[num2 + 1],
                        B = numArray[num2]
                    };
                    connectedPixel.m_color      = pxColor;
                    connectedPixel.m_height     = num4;
                    connectedPixel.m_width      = num3;
                    connectedPixel.m_topYCor    = (short)yCor;
                    connectedPixel.m_bottomYCor = (short)yCor1;
                    connectedPixel.m_leftXCor   = (short)xCor;
                    connectedPixel.m_rightXCor  = (short)xCor1;
                    ConnectedPixel connectedPixel1 = connectedPixel;
                    ConnectedCoordinate.CheckSpecialSeperatedDotCharacter(connectedPixel1, connectedPixels, characterInfo, characterInfo1, keyValuePair);
                    ConnectedCoordinate.GetbackgroundColor(connectedPixel1, ref numArray, width, num1);
                    connectedPixels.Add(connectedPixel1);
                }
            }
            return(connectedPixels);
        }
        private void GenerateChracterPixel()
        {
            Regex regex = new Regex("(?<xCor>(\\d)+)[,](?<yCor>(\\d)+)");

            string[] strArrays = new string[] { "TypeOne", "TypeTwo" };
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                string str        = strArrays[i];
                string str1       = str;
                var    collection =
                    from subitem in this.XmlDoc.Descendants(str).Elements <XElement>("CharacterInfo")
                    let xElement = subitem.Element("ParamValue")
                                   where xElement != null
                                   let element = subitem.Element("PixelInfo")
                                                 where element != null
                                                 select new { Character = char.Parse(xElement.Value), PixelInfo = element.Value, CharacterDirection = Direction.Horizontal, FontWeight = (str1 == "TypeTwo" ? FontWeight.Bold : FontWeight.Normal), Pixel = regex.Matches(element.Value) };
                foreach (var variable in collection)
                {
                    List <PixelPoint> list = (
                        from Match oMatch in variable.Pixel
                        let xCor = short.Parse(oMatch.Groups["xCor"].Value)
                                   let yCor = short.Parse(oMatch.Groups["yCor"].Value)
                                              select new PixelPoint(xCor, yCor)).ToList <PixelPoint>();
                    CharacterInfo characterInfo = new CharacterInfo();
                    if (list.Count > 0)
                    {
                        list.Sort((PixelPoint object1, PixelPoint object2) => object1.XCor.CompareTo(object2.XCor));
                        PixelPoint item = list[list.Count - 1];
                        short      num  = item.XCor;
                        item = list[0];
                        byte num1 = (byte)(num - item.XCor + 1);
                        list.Sort((PixelPoint object1, PixelPoint object2) => object1.YCor.CompareTo(object2.YCor));
                        item = list[list.Count - 1];
                        short num2 = item.YCor;
                        item = list[0];
                        byte num3 = (byte)(num2 - item.YCor + 1);
                        bool[,] flagArray = new bool[num1, num3];
                        foreach (PixelPoint pixelPoint in list)
                        {
                            flagArray[pixelPoint.XCor, pixelPoint.YCor] = true;
                        }
                        characterInfo.Character          = variable.Character;
                        characterInfo.m_fontWeight       = variable.FontWeight;
                        characterInfo.CharacterDirection = variable.CharacterDirection;
                        characterInfo.m_pixelCoordinate  = flagArray;
                        characterInfo.Width  = num1;
                        characterInfo.Height = num3;
                        this.m_characterInfo.Add(characterInfo);
                        CharacterInfo characterInfo1 = new CharacterInfo()
                        {
                            Character          = variable.Character,
                            m_fontWeight       = variable.FontWeight,
                            CharacterDirection = Direction.Vertical,
                            m_pixelCoordinate  = CharacterPixel.ChangeOrderVerticalLeftToRight(flagArray),
                            Width  = num3,
                            Height = num1
                        };
                        characterInfo = characterInfo1;
                        this.m_characterInfo.Add(characterInfo);
                    }
                }
            }
        }