/// <summary> /// 获取指定位置与大小的游戏界面颜色(用于判别界面是否有改变) /// </summary> /// <param name="xy"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public string GetColorForPoint(string xy, int width = 4, int height = 1) { using (Bitmap bmp = new Bitmap(this.GetGameBitmap)) { return(FunctionBitmap.GetColorData(bmp, xy, width, height)); } }
/// <summary> /// 刷新游戏缩略图 /// </summary> private Bitmap RefreshGameWindow_pictureBox() { if (GameWindow_GamePicture_pictureBox.Image != null) { Image i = GameWindow_GamePicture_pictureBox.Image; GameWindow_GamePicture_pictureBox.Image = null; i.Dispose(); } try { if (GlobalObject.GameHandle.IsSuccess) { var temp = GlobalObject.GameHandle.GetGameBitmap(); GameWindow_GamePicture_pictureBox.Image = FunctionBitmap.ResizeImage(temp, 200, 120, false); return(temp); } else { GameWindow_GamePicture_pictureBox.Image = FunctionBitmap.ResizeImage(Properties.Resources.CrawlFailed, 200, 120, true); } } catch (Exception) { /*************** * 在这里加入失败图像 ***************/ if (GameWindow_GamePicture_pictureBox.Image != null) { Image i = GameWindow_GamePicture_pictureBox.Image; GameWindow_GamePicture_pictureBox.Image = FunctionBitmap.ResizeImage(Properties.Resources.CrawlFailed, 200, 120, true); i.Dispose(); } } return(null); }
/// <summary> /// 抓取前台模式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GameWindow_Desktop_button_Click(object sender, EventArgs e) { GlobalObject.GameHandle = new GameHandleClass(); int SH = Screen.PrimaryScreen.Bounds.Height; //屏幕分辨率高度 int SW = Screen.PrimaryScreen.Bounds.Width; //屏幕分辨率宽度 Point xy = new Point(); using (var bmp = FunctionBitmap.CopyWindow()) { if (FunctionJudge.IsGameInWin(bmp, out xy)) { GlobalObject.GameHandle = new GameHandleClass(); GlobalObject.GameHandle.Handle = IntPtr.Zero; GlobalObject.GameHandle.Mode = FunctionHandle.MODE.Desktop; GlobalObject.GameHandle.XY = xy; this.GameWindow_Message_textBox.Text = "前台模式抓取成功"; this.GameWindow_Message_textBox.BackColor = Color.Lime; RefreshGameWindow_pictureBox(); } else { GlobalObject.GameHandle = new GameHandleClass(); this.GameWindow_Message_textBox.Text = "前台模式抓取失败"; this.GameWindow_Message_textBox.BackColor = Color.Red; RefreshGameWindow_pictureBox(); } } }
/// <summary> /// 获取游戏窗口图像(*注意析构图像) /// </summary> /// <returns>游戏图像</returns> public Bitmap GetGameBitmap() { if (!IsSuccess) { return(null); } if (_photo != null) { _photo?.Dispose(); _photo = null; } if (_mode == FunctionHandle.MODE.Handle) { _photo = FunctionBitmap.PrtGameWindow(this); } else if (_mode == FunctionHandle.MODE.Desktop) { _photo = FunctionBitmap.CutImage(FunctionBitmap.CopyWindow(), _xy.X, _xy.Y, 800, 480, true); } else if (_mode == FunctionHandle.MODE.Chorme) { _photo = FunctionBitmap.CutImage(FunctionBitmap.PrtGameWindow(this), _xy.X, _xy.Y, 800, 480, true); } else { return(null); } return(_photo); }
private void CatchData_GetData_Click(object sender, EventArgs e) { CatchData = new DataJudge("0,0 @ 000000", "CatchData"); CatchData_GetDataShow.Text = ""; try { CatchData.XYToStr = CatchData_CatchXY.Text; CatchData_GetDataShow.Text += CatchData.XYToStr + " @ "; string[] wh = CatchData_CatchWH.Text.Split(','); CatchData.Color = FunctionBitmap.GetColorData(new Bitmap(CatchData_GamePicture.Image), CatchData.XYToStr, Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1])); CatchData_GetDataShow.Text += CatchData.Color; } catch (Exception) { CatchData_GetDataShow.Text = "颜色信息获取失败,请检查" + Environment.NewLine + " 1.是否成功获取游戏窗口" + Environment.NewLine + " 2.数值输入是否错误"; } }
/// <summary> /// 点击树状图上的某一节点,刷新图像 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GameWindow_treeView_Click(object sender, EventArgs e) { if (GameWindow_HandleList_treeView.SelectedNode != null) { // 将当前节点文本添加到文本框 this.GameWindow_InputIntPtr_textBox.Text = GameWindow_HandleList_treeView.SelectedNode.Text; if (GameWindow_GamePicture_pictureBox.Image != null) { Image i = GameWindow_GamePicture_pictureBox.Image; GameWindow_GamePicture_pictureBox.Image = null; i.Dispose(); } try { GameWindow_GamePicture_pictureBox.Image = FunctionBitmap.ResizeImage(FunctionBitmap.PrtGameWindow(Function.Functions.StrToIntPtr(GameWindow_HandleList_treeView.SelectedNode.Text)), 200, 120, true); } catch (Exception) { /*************** * 在这里加入失败图像 ***************/ } } }