/// <summary> /// Controls to draw cursor or crosshair /// </summary> /// <param name="bmp">bitmap too draw</param> /// <param name="wRect">Caption rect to calculate cursor</param> /// <param name="Profil">setting prolfie</param> /// <param name="CursorPosition">cursor position</param> /// <param name="myBrush">draw brush</param> /// <returns>bitmap with drawings</returns> public static Bitmap DrawExtras(Bitmap bmp, Rectangle wRect, ProfileData Profil, Point CursorPosition, SolidBrush myBrush) { try { if (bmp == null) { return(new Bitmap(wRect.Width, wRect.Height, PixelFormat.Format32bppArgb)); } Graphics g = System.Drawing.Graphics.FromImage(bmp); if (Profil.ShowCrosshair) { GDIGraphicTools.DrawCrosshair(g, wRect.Width, wRect.Height, Profil.ShowCrosshair3D); } if (Profil.ShowCursor) { GDIGraphicTools.DrawCursor(g, wRect.X, wRect.Y, wRect.Width, wRect.Height, CursorPosition, Profil.CursorCorrection, Profil.CursorCorrectionAdjWidth, Profil.CursorCorrectionAdjHeight, myBrush, Profil.CursorSize, Profil.ShowCursor3D); } // cursor g.Dispose(); } catch { } return(bmp); }
public void acceptCallback(IAsyncResult ar) { Socket listener = null; Socket handler = null; try { if (this.Profil != null) { listener = (Socket)ar.AsyncState; try { handler = listener.EndAccept(ar); } catch { if (TCPServer != null) { TCPServer.Close(); TCPServer = null; } return; } NetworkStream ns = new NetworkStream(handler, true); jgpEncoder = GDIGraphicTools.GetEncoder(ImageFormat.Jpeg); myEncoderParameters.Param[0] = new EncoderParameter(myEncoder, this.hScrollImageQuality.Value); cptRect.GetGameWindowRect(this.tbProcess.Text, Profil); // to split it will speed up the loop; keep it simple stupid if (cbUseGDI.Checked) { // gdi loop while ((handler.Connected) && (blStop == false)) { try { ms.SetLength(0); bm = CaptureSpecificWindow(cptRect.getRect()); if ((Profil.ShowCrosshair) || (Profil.ShowCursor)) { bm = GDIGraphicTools.DrawExtras(bm, cptRect.getRect(), Profil, Cursor.Position, myBrush); } bm.Save(ms, jgpEncoder, myEncoderParameters); } catch { ms.SetLength(0); } // send data try { if ((ms != null) && (ms.Length > 0)) { // may be put it on separate method byte[] mybyt = ms.ToArray(); if (mybyt.Length > 0) { lenght = mybyt.Length; lenbyte = BitConverter.GetBytes(lenght); ns.Write(lenbyte, 0, lenbyte.Length); ns.Flush(); ns.Write(mybyt, 0, mybyt.Length); ns.Flush(); } } } catch { blStop = true; } } // while } else { dx = new DirectX(); dx.SetRect(cptRect.getRect()); while ((handler.Connected) && (blStop == false)) { try { ms.SetLength(0); bm = dx.Capture(); if ((Profil.ShowCrosshair) || (Profil.ShowCursor)) { bm = GDIGraphicTools.DrawExtras(bm, cptRect.getRect(), Profil, Cursor.Position, myBrush); // needs to speed up } bm.Save(ms, jgpEncoder, myEncoderParameters); } catch { ms.SetLength(0); } // send data try { if ((ms != null) && (ms.Length > 0)) { // may be put it on separate method byte[] mybyt = ms.ToArray(); if (mybyt.Length > 0) { lenght = mybyt.Length; lenbyte = BitConverter.GetBytes(lenght); ns.Write(lenbyte, 0, lenbyte.Length); ns.Flush(); ns.Write(mybyt, 0, mybyt.Length); ns.Flush(); } } } catch { blStop = true; } } // while dx.close(); dx = null; } // gdi or directx Invoke((MethodInvoker) delegate { ServerStopped(); }); } } catch (Exception ex) { MessageBox.Show("Error on starting Server (Callback). \r\n" + ex.Message); blStop = true; } finally { if (ms != null) { try { ms.Close(); ms = null; } catch { } } if ((handler != null) && (handler.Connected)) { try { handler.Shutdown(SocketShutdown.Both); handler.Disconnect(false); } catch { } } if (TCPServer != null) { try { TCPServer.Close(); TCPServer = null; } catch { } } } } // acceptCallback