Advertisement
Guest User

Untitled

a guest
Jan 31st, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. [DllImport("user32.dll", SetLastError = true)]
  2. static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
  3.  
  4. [StructLayout(LayoutKind.Sequential)]
  5. private struct RECT
  6. {
  7. public int Left;
  8. public int Top;
  9. public int Right;
  10. public int Bottom;
  11. }
  12.  
  13. private static Bitmap ScreenGrab(int x, int y, int width, int height)
  14. {
  15. IntPtr hwnd = System.Diagnostics.Process.GetProcessesByName("MapleStory")[0].MainWindowHandle;
  16. RECT rectRAW = new RECT();
  17. GetWindowRect(hwnd, ref rectRAW);
  18.  
  19. Rectangle rect = new Rectangle(rectRAW.Left, rectRAW.Top, rectRAW.Right - rectRAW.Left, rectRAW.Bottom - rectRAW.Top);
  20. rect = new Rectangle(rect.X + x, rect.Y + y, width, height);
  21.  
  22. // Get information about the screen
  23. using (Graphics browserGraphics = Graphics.FromHwnd(hwnd))
  24. // apply that info to a bitmap...
  25. using (Bitmap screenshot = new Bitmap(rect.Width, rect.Height, browserGraphics))
  26. // and create an Graphics to manipulate that bitmap.
  27. using (Graphics imageGraphics = Graphics.FromImage(screenshot))
  28. {
  29. imageGraphics.CopyFromScreen(rect.X, rect.Y, 0, 0, new Size(rect.Width, rect.Height));
  30. return (Bitmap)screenshot.Clone();
  31. }
  32. }
  33.  
  34. ----------------------------
  35.  
  36. case "level":
  37. int level = int.Parse(splitted[1]);
  38. Send(new UpdatePlayerStatMessage()
  39. {
  40. ItemReaction = false,
  41. Stats =
  42. {
  43. { PlayerStats.Level, level },
  44. { PlayerStats.Exp, 0 },
  45. }
  46. });
  47. System.Threading.Thread.Sleep(1500);
  48. try
  49. {
  50. string filename = "C:/ExpTable.png";
  51.  
  52. if (!File.Exists(filename))
  53. {
  54. using (Bitmap bmp = new Bitmap(168 + 68, 34 * 50, PixelFormat.Format32bppArgb))
  55. {
  56. bmp.Save(filename, ImageFormat.Png);
  57. }
  58. }
  59.  
  60. using (Bitmap lvlBmp = ScreenGrab(7, 591, 68, 34))
  61. using (Bitmap expBmp = ScreenGrab(399, 591, 168, 34))
  62. using (Bitmap savedBmp = (Bitmap)Bitmap.FromStream(new MemoryStream(File.ReadAllBytes(filename))))
  63. using (Graphics graphics = Graphics.FromImage(savedBmp))
  64. {
  65. graphics.DrawImage(lvlBmp, 0, (level - 200) * 34);
  66. graphics.DrawImage(expBmp, lvlBmp.Width, (level - 200) * 34);
  67. savedBmp.Save(filename, ImageFormat.Png);
  68. }
  69.  
  70. Console.WriteLine("saved " + level);
  71. }
  72. catch (Exception e)
  73. {
  74. Console.WriteLine(e);
  75. }
  76. break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement