using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ScreenCapture.NET;
///
/// Represents a using the .
///
public class GDIScreenCaptureService : IScreenCaptureService
{
#region Properties & Fields
private readonly Dictionary _screenCaptures = new();
private bool _isDisposed;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
public GDIScreenCaptureService()
{
}
~GDIScreenCaptureService() => Dispose();
#endregion
#region Methods
///
public IEnumerable GetGraphicsCards()
{
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
return [new GraphicsCard(0, "Default", 0, 0)];
}
///
public IEnumerable GetDisplays(GraphicsCard graphicsCard)
{
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
Screen screen = Screen.PrimaryScreen!;
return [new Display(0, screen.DeviceName, screen.Bounds.Width, screen.Bounds.Height, Rotation.None, graphicsCard)];
}
///
IScreenCapture IScreenCaptureService.GetScreenCapture(Display display) => GetScreenCapture(display);
public GDIScreenCapture GetScreenCapture(Display display)
{
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (!_screenCaptures.TryGetValue(display, out GDIScreenCapture? screenCapture))
_screenCaptures.Add(display, screenCapture = new GDIScreenCapture(display));
return screenCapture;
}
///
public void Dispose()
{
if (_isDisposed) return;
foreach (GDIScreenCapture screenCapture in _screenCaptures.Values)
screenCapture.Dispose();
_screenCaptures.Clear();
GC.SuppressFinalize(this);
_isDisposed = true;
}
#endregion
}