예제 #1
0
파일: MainForm.cs 프로젝트: kaysonli/zoneky
        protected override void DefWndProc(ref Message m)
        {
            playground = configLoader.GetPlaygroundInfo(this.gameType);
            this.blobWnd.Width = playground.Width;
            this.blobWnd.Height = playground.Height;
            switch (m.Msg)
            {
                case 0x8888:
                    {
                        this.blobWnd.BlobRects = null;
                        this.blobWnd.Invalidate();
                        this.blobWnd.Hide();
                        IntPtr foregroundWindow = GetForegroundWindow();
                        RECT lpRect = new RECT();
                        GetWindowRect(foregroundWindow, ref lpRect);
                        int left = lpRect.Left;
                        int top = lpRect.Top;
                        this.imageX = left + playground.Width + playground.MarginLeft + playground.Gutter;
                        this.imageY = top + playground.MarginTop;
                        Bitmap bitmap = this.graber.TakePhoto(playground.Width, playground.Height, left + playground.MarginLeft, this.imageY);
                        Bitmap bitmap2 = this.graber.TakePhoto(playground.Width, playground.Height, this.imageX, this.imageY);
                        if (this.checkBoxSaveImg.Checked)
                        {
                            try
                            {
                                string str = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_1.jpg";
                                string text1 = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_2.jpg";
                                bitmap.Save(this.savePath + @"\" + str, ImageFormat.Jpeg);
            //								bitmap2.Save(this.savePath + @"\" + text1, ImageFormat.Jpeg);
                            }
                            catch(Exception ex)
                            {

                            }
                        }
                        Bitmap image = (Bitmap) bitmap.Clone();
                        Bitmap bitmap4 = (Bitmap) bitmap2.Clone();
                        this.differenceFilter.OverlayImage = bitmap4;
                        Bitmap bitmap5 = this.differenceFilter.Apply(image);
                        Bitmap bitmap6 = this.grayFilter.Apply(bitmap5);
                        Bitmap bitmap7 = this.thresholdFilter.Apply(bitmap6);
            //						this.pictureBox1.Image = bitmap7;
                        this.bc.ProcessImage(bitmap7);
                        this.diffRects = this.bc.GetObjectsRectangles();
                        this.blobWnd.Location = new Point(this.imageX, this.imageY);
                        this.blobWnd.BlobRects = this.diffRects;
                        SetWindowPos(this.blobWnd.Handle.ToInt32(), -1, this.blobWnd.Location.X, this.blobWnd.Location.Y, playground.Width, playground.Height, 1);
                        this.blobWnd.Show();
                        this.blobWnd.Invalidate();
                        return;
                    }
                case 0x9999:
                    this.blobWnd.Hide();
                    return;
            }
            base.DefWndProc(ref m);
        }
예제 #2
0
 public GameWindowInfo GetPlaygroundInfo(GameType gameType)
 {
     GameWindowInfo info = new GameWindowInfo();
     var startup = doc.SelectSingleNode("config/startup");
     if(startup == null)
     {
         return info;
     }
     foreach(XmlNode game in startup.ChildNodes)
     {
         GameType type = (GameType)int.Parse(game.Attributes["type"].Value);
         info.MarginLeft = int.Parse(game.Attributes["marginLeft"].Value);
         info.MarginTop = int.Parse(game.Attributes["marginTop"].Value);
         info.Width = int.Parse(game.Attributes["width"].Value);
         info.Height = int.Parse(game.Attributes["height"].Value);
         info.Gutter = int.Parse(game.Attributes["gutter"].Value);
         if(type == gameType)
         {
             return info;
         }
     }
     return info;
 }