Guest User

Untitled

a guest
Jun 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. //Use this to test it.
  2. Rectangle rect = new Rectangle(0,0150,150);
  3. Capture(rect);
  4.  
  5. public void Capture(Rectangle rect)
  6. {
  7. var times = new List<long>();
  8.  
  9. for (int i = 0; i < 100; i++)
  10. {
  11. using (Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb))
  12. {
  13. using (Graphics gdest = Graphics.FromImage(bmp))
  14. {
  15. using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
  16. {
  17.  
  18. IntPtr hSrcDC = gsrc.GetHdc();
  19. IntPtr hDC = gdest.GetHdc();
  20.  
  21. Stopwatch sw = new Stopwatch();
  22.  
  23. sw.Start();
  24. int retval = BitBlt(hDC, 0, 0, rect.Width, rect.Height, hSrcDC, rect.Left, rect.Top, (int)CopyPixelOperation.SourceCopy);
  25. sw.Stop();
  26.  
  27. gdest.ReleaseHdc();
  28. gsrc.ReleaseHdc();
  29.  
  30. times.Add(sw.ElapsedMilliseconds);
  31. }
  32. }
  33. }
  34. }
  35.  
  36. var mean = times.Sum(x => x) / times.Count;
  37. Console.WriteLine("Mean: " + mean);
  38. }
Add Comment
Please, Sign In to add comment