using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using RichCreator.Utility.Captures.DesktopDuplication;
|
|
namespace RichCreator.Utility.Captures
|
{
|
public class DesktopDuplicationCapture : ICapture
|
{
|
private DesktopDuplicator capture= new DesktopDuplicator(0);
|
|
public Bitmap CaptureScreen()
|
{
|
DesktopFrame frame = null;
|
try
|
{
|
frame = capture.GetLatestFrame();
|
}
|
catch
|
{
|
|
return null;
|
}
|
|
if (frame != null)
|
{
|
//LabelCursor.Location = frame.CursorLocation;
|
//LabelCursor.Visible = frame.CursorVisible;
|
//Debug.WriteLine("--------------------------------------------------------");
|
//foreach (var moved in frame.MovedRegions)
|
//{
|
// Debug.WriteLine(String.Format("Moved: {0} -> {1}", moved.Source, moved.Destination));
|
// MovedRegion.Location = moved.Destination.Location;
|
// MovedRegion.Size = moved.Destination.Size;
|
//}
|
//foreach (var updated in frame.UpdatedRegions)
|
//{
|
// Debug.WriteLine(String.Format("Updated: {0}", updated.ToString()));
|
// UpdatedRegion.Location = updated.Location;
|
// UpdatedRegion.Size = updated.Size;
|
//}
|
|
//bool black = true;
|
//Color b = Color.FromArgb(0, 0, 0);
|
//for (int y = 0; y < 2; y++)
|
//{
|
// for (int x = 0; x < 2; x++)
|
// {
|
// if (frame.DesktopImage.GetPixel(x, y) != b)
|
// {
|
// black = false;
|
// }
|
// }
|
// if (!black)
|
// {
|
// break;
|
// }
|
//}
|
|
|
//if (black)
|
//{
|
// black = false;
|
//}
|
if (frame.UpdatedRegions.Length <= 0)
|
{
|
return null;
|
}
|
return frame.DesktopImage;
|
}
|
return null;
|
}
|
|
public Bitmap CaptureScreen(int x, int y, int width, int height)
|
{
|
using (Bitmap screen = CaptureScreen())
|
{
|
if (screen == null)
|
{
|
return null;
|
}
|
Bitmap screenRect = screen.Clone(new Rectangle(x, y, width, height), screen.PixelFormat);
|
return screenRect;
|
}
|
|
}
|
}
|
}
|