using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Drawing.Imaging;
|
using System.IO;
|
using System.Linq;
|
using System.Runtime.InteropServices;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Media.Imaging;
|
using Emgu.CV;
|
using Emgu.CV.Structure;
|
|
namespace RichCreator.Utility.Captures
|
{
|
public class ScreenCapture
|
{
|
private DesktopDuplicationCapture capture = new DesktopDuplicationCapture();
|
private BitBltCapture bitCapture = new BitBltCapture();
|
private ScreenCapture()
|
{}
|
|
/// <summary>
|
/// 截屏
|
/// </summary>
|
/// <returns></returns>
|
public Bitmap CaptureScreen()
|
{
|
Bitmap bm= capture.CaptureScreen();
|
if (bm == null)
|
{
|
bm = bitCapture.CaptureScreen();
|
}
|
return bm;
|
}
|
|
|
public Image<Rgb, byte> CaptureScreenReturnImage()
|
{
|
Bitmap bitmap = CaptureScreen();
|
Image<Rgb, byte> image = new Image<Rgb, byte>(bitmap);
|
return image;
|
}
|
|
/// <summary>
|
/// 截取指定区域
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
/// <param name="width"></param>
|
/// <param name="height"></param>
|
/// <returns></returns>
|
public Bitmap CaptureScreen(Int32 x,Int32 y,Int32 width,Int32 height)
|
{
|
using (Bitmap bm = CaptureScreen())
|
{
|
Bitmap screenRect = bm.Clone(new Rectangle(x, y, width, height), bm.PixelFormat);
|
return screenRect;
|
}
|
}
|
|
#region sington
|
private static ScreenCapture instance;
|
private static object lockHelper = new object();
|
public static ScreenCapture Instance
|
{
|
get
|
{
|
if (instance == null)
|
{
|
lock (lockHelper)
|
{
|
if (instance == null)
|
{
|
instance = new ScreenCapture();
|
}
|
}
|
}
|
return instance;
|
}
|
}
|
|
#endregion
|
|
}
|
}
|