资源简介
窗口截图C#代码
可后台截取DX窗口
使用SharpDX库
GraphicsCapture Win32.DesktopDuplication
也可以抓取桌面
代码片段和文件信息
using System;
using System.Drawing;
using System.Drawing.Imaging;
using SharpDX;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using Win32.BitBlt.Interop;
using Win32.Shared;
using Win32.Shared.Interfaces;
using Device = SharpDX.Direct3D11.Device;
using Rectangle = System.Drawing.Rectangle;
namespace Win32.BitBlt
{
internal class BitBlt : ICaptureMethod
{
private IntPtr _hWnd;
public void Dispose()
{
// Nothing to do
}
public bool IsCapturing { get; private set; }
public void StartCapture(IntPtr hWnd Device device Factory factory)
{
var picker = new WindowPicker();
_hWnd = picker.PickCaptureTarget(hWnd);
if (_hWnd == IntPtr.Zero)
return;
IsCapturing = true;
}
public Texture2D TryGetNextframeAsTexture2D(Device device)
{
if (_hWnd == IntPtr.Zero)
return null;
var hdcSrc = NativeMethods.GetDCEx(_hWnd IntPtr.Zero DeviceContextValues.Window | DeviceContextValues.Cache | DeviceContextValues.LockWindowUpdate);
var hdcDest = NativeMethods.CreateCompatibleDC(hdcSrc);
NativeMethods.GetWindowRect(_hWnd out var rect);
var (width height) = (rect.Right - rect.Left rect.Bottom - rect.Top);
var hBitmap = NativeMethods.CreateCompatibleBitmap(hdcSrc width height);
var hOld = NativeMethods.Selectobject(hdcDest hBitmap);
NativeMethods.BitBlt(hdcDest 0 0 width height hdcSrc 0 0 TernaryRasterOperations.SRCCOPY);
NativeMethods.Selectobject(hdcDest hOld);
NativeMethods.DeleteDC(hdcDest);
NativeMethods.ReleaseDC(_hWnd hdcSrc);
using var img = Image.FromHbitmap(hBitmap);
NativeMethods.Deleteobject(hBitmap);
using var bitmap = img.Clone(Rectangle.FromLTRB(0 0 width height) PixelFormat.Format32bppArgb);
var bits = bitmap.LockBits(Rectangle.FromLTRB(0 0 width height) ImageLockMode.ReadOnly img.PixelFormat);
var data = new DataBox { DataPointer = bits.Scan0 RowPitch = bits.Width * 4 SlicePitch = bits.Height };
var texture2dDescription = new Texture2DDescription
{
ArraySize = 1
BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget
CpuAccessFlags = CpuAccessFlags.None
Format = Format.B8G8R8A8_UNorm
Height = height
MipLevels = 1
SampleDescription = new SampleDescription(1 0)
Usage = ResourceUsage.Default
Width = width
};
var texture2d = new Texture2D(device texture2dDescription new[] { data });
bitmap.UnlockBits(bits);
return texture2d;
}
public void StopCapture()
{
_hWnd = IntPtr.Zero;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5653 2020-04-18 20:37 窗口截图(可后台截取DX窗口)\Source\CSharp窗口截图.sln
....... 184 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\App.config
....... 3005 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\BitBlt.cs
....... 2872 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Interop\DeviceContextValues.cs
....... 1460 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Interop\NativeMethods.cs
....... 399 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Interop\RECT.cs
....... 1711 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Interop\TernaryRasterOperations.cs
文件 9696 2020-04-18 20:36 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\obj\Debug\Win32.BitBlt.csprojAssemblyReference.cache
....... 520 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\packages.config
....... 327 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Program.cs
....... 457 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Shader.fx
....... 4419 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.BitBlt\Win32.BitBlt.csproj
....... 184 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\App.config
....... 2208 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\DesktopDuplication.cs
文件 2924 2020-04-18 20:36 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\obj\Debug\Win32.DesktopDuplication.csprojAssemblyReference.cache
....... 284 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\packages.config
....... 347 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\Program.cs
....... 457 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\Shader.fx
....... 3242 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DesktopDuplication\Win32.DesktopDuplication.csproj
....... 184 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\App.config
....... 2286 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\DwmSharedSurface.cs
....... 994 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\Interop\NativeMethods.cs
文件 8486 2020-04-18 20:36 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\obj\Debug\Win32.DwmSharedSurface.csprojAssemblyReference.cache
....... 520 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\packages.config
....... 347 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\Program.cs
....... 457 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\Shader.fx
....... 4273 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmSharedSurface\Win32.DwmSharedSurface.csproj
....... 184 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmThumbnail\App.config
....... 381 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmThumbnail\App.xaml
....... 340 2019-11-18 20:04 窗口截图(可后台截取DX窗口)\Source\Win32.DwmThumbnail\App.xaml.cs
............此处省略96个文件信息
- 上一篇:c# winform 串口电子秤集成开发
- 下一篇:command模式的撤销重做
相关资源
- c# winform 串口电子秤集成开发
- C#窗口实现百度云人脸识别
- VS2017 C#代码配色方案-monokai
- 数据库管理系统
- 大富翁简版小游戏
- C# .net版 RSA 公钥加密私钥解密 私钥加
- c#窗体应用程序实现对数据库的增删查
- C#网络爬虫源码.zip
- 操作系统四个实验[C#版]
- 测绘工程导线测量程序设计
- c# win10ssk皮肤文件
- C#影院信息管理系统
- C#读取和导出EXCEL类库 AppLibrary.dll
- 微信企业付款到银行卡c#代码
- 个人收支管理
- C#膨胀腐蚀算法实现vs2017可用
- 基于ASP.net餐饮管理系统
- C#Storyboard实现图片旋转
- C#编写串口调试助手完整项目
- C# Chart表格多个ChartArea、Series显示;
- 简单收银系统 完整源代码
- c#调用MATLAB的具体
-
通过xsd产生C#实体类解析xm
l或生成 - C# 五子棋(初学C#设计)
- C#获取实时天气预报
- C#基于UDP的点对点语音聊天程序
- c#实现野人与传教士过河问题以及动画
- C#(VS2017)阿里云云市场发票内容识别
- C#(VS2017)百度语音识别demo
- winform画图软件
评论
共有 条评论