private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Bitmap bitmap = CaptureImage.Captuer(wzqProcess);

            if (bitmap == null)
            {
                return;
            }

            //裁剪棋盘
            int width = baseConfiguration.GameBoardInsideWidth;

            chessStep = width * 15 / 14 / 15;
            Bitmap   wzqBoardImage = new Bitmap(width * 15 / 14, width * 15 / 14);
            Graphics g             = Graphics.FromImage(wzqBoardImage);

            g.DrawImage(bitmap,
                        new Rectangle(0, 0, wzqBoardImage.Width, wzqBoardImage.Height),
                        new Rectangle(227 - chessStep / 2, 129 - chessStep / 2, wzqBoardImage.Width, wzqBoardImage.Height),
                        GraphicsUnit.Pixel);
            g.Dispose();

            //识别棋子
            List <Tuple <int, int, int> > chessPointList = GetChessCoorinate(wzqBoardImage);

            ChessRecognized?.Invoke(this, new ChessRecongizedEventArgs {
                ChessPointList = chessPointList
            });
        }
Exemple #2
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Bitmap bitmap = CaptureImage.Captuer(wzqProcess);

            if (bitmap == null)
            {
                return;
            }

            //裁剪棋盘
            int width = baseConfiguration.GameBoardInsideWidth;

            chessStep = width * 15 / 14 / 15;
            Bitmap   wzqBoardImage = new Bitmap(width * 15 / 14, width * 15 / 14);
            Graphics g             = Graphics.FromImage(wzqBoardImage);

            g.DrawImage(bitmap,
                        new Rectangle(0, 0, wzqBoardImage.Width, wzqBoardImage.Height),
                        new Rectangle(227 - chessStep / 2, 129 - chessStep / 2, wzqBoardImage.Width, wzqBoardImage.Height),
                        GraphicsUnit.Pixel);
            g.Dispose();

            //识别棋子
            List <Tuple <int, int, int> > chessPointList = GetChessCoorinate(wzqBoardImage);

            Console.WriteLine("Captured -- " + DateTime.Now.ToString());

            //把旧棋子合并到新棋子中
            foreach (var item in lastChessPointList)
            {
                if (chessPointList.Contains(item) == false)
                {
                    chessPointList.Add(item);
                }
            }

            //判断棋子有没增加
            if (chessPointList.Count > lastChessPointList.Count)
            {
                lastChessPointList.Clear();
                foreach (var item in chessPointList)
                {
                    lastChessPointList.Add(item);
                }
                ChessRecognized?.Invoke(this, new ChessRecongizedEventArgs {
                    ChessPointList = chessPointList
                });
            }
        }