Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Use this to test it.
- Rectangle rect = new Rectangle(0,0150,150);
- Capture(rect);
- public void Capture(Rectangle rect)
- {
- var times = new List<long>();
- for (int i = 0; i < 100; i++)
- {
- using (Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb))
- {
- using (Graphics gdest = Graphics.FromImage(bmp))
- {
- using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
- {
- IntPtr hSrcDC = gsrc.GetHdc();
- IntPtr hDC = gdest.GetHdc();
- Stopwatch sw = new Stopwatch();
- sw.Start();
- int retval = BitBlt(hDC, 0, 0, rect.Width, rect.Height, hSrcDC, rect.Left, rect.Top, (int)CopyPixelOperation.SourceCopy);
- sw.Stop();
- gdest.ReleaseHdc();
- gsrc.ReleaseHdc();
- times.Add(sw.ElapsedMilliseconds);
- }
- }
- }
- }
- var mean = times.Sum(x => x) / times.Count;
- Console.WriteLine("Mean: " + mean);
- }
Add Comment
Please, Sign In to add comment