如何从ID3D11Texture2D访问像素数据? [英] How to access pixels data from ID3D11Texture2D?

查看:143
本文介绍了如何从ID3D11Texture2D访问像素数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows桌面复制API来创建自己的镜像协议.我有这段代码:

 //获取新框架HRESULT hr = m_DeskDupl-> AcquireNextFrame(500,& FrameInfo,& DesktopResource);如果(hr == DXGI_ERROR_WAIT_TIMEOUT){*超时= true;返回DUPL_RETURN_SUCCESS;} 

这是 FrameInfo 结构:

 `typedef struct _FRAME_DATA {ID3D11Texture2D *框架;DXGI_OUTDUPL_FRAME_INFO FrameInfo;_Field_size_bytes _((MoveCount * sizeof(DXGI_OUTDUPL_MOVE_RECT))+(DirtyCount * sizeof(RECT)))BYTE * MetaData;UINT DirtyCount;UINT MoveCount;} FRAME_DATA;` 

我想从 ID3D11Texture2D * Frame中提取像素缓冲区; 如何在 BYTE * unsigned char * 上提取并具有RGB序列?谢谢!

解决方案

您需要使用 ID3D11Device :: CreateTexture2D 创建具有CPU读取访问权限的相同大小的第二个纹理,复制整个帧或仅复制使用 ID3D11DeviceContext :: CopyResource ID3D11DeviceContext :: CopySubresourceRegion 在GPU上更新了此纹理的零件(可以使用 IDXGIOutputDuplication :: GetFrameDirtyRects <检索哪些零件已更新/code>和 IDXGIOutputDuplication :: GetFrameMoveRects ),使用 ID3D11DeviceContext :: Map 映射第二个纹理以使其可由CPU访问,从而为您提供 D3D11_MAPPED_SUBRESOURCE 结构包含指向具有帧数据的缓冲区及其大小的指针,这就是您要寻找的.

Microsoft提供了更详细的桌面复制API使用示例执行上述所有步骤.

还有一个 解决方案

You need to create a second texture of the same size with CPU read access using ID3D11Device::CreateTexture2D, copy whole frame or just updated parts to this texture on GPU using ID3D11DeviceContext::CopyResource or ID3D11DeviceContext::CopySubresourceRegion (it is possible to retrieve which parts were updated using IDXGIOutputDuplication::GetFrameDirtyRects and IDXGIOutputDuplication::GetFrameMoveRects), map second texture to make it accessible by CPU using ID3D11DeviceContext::Map which gives you D3D11_MAPPED_SUBRESOURCE struct containing pointer to buffer with frame data and it's size, that is what you are looking for.

Microsoft provides a rather detailed Desktop Duplication API usage sample implementing all the steps mentioned above.

There is also a straight sample demonstrating how to save ID3D11Texture2D data to file.

这篇关于如何从ID3D11Texture2D访问像素数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆