gpt4 book ai didi

c++ - DXGI 屏幕捕获图像失真

转载 作者:行者123 更新时间:2023-11-30 03:22:33 26 4
gpt4 key购买 nike

不仅 fps 从 60 下降到 20-21,而且图像看起来像这样扭曲。第二张图应该是这样的

What it looks like What it should look like

if (captureVideo == 1) {
pNewTexture = NULL;

// Use the IDXGISwapChain::GetBuffer API to retrieve a swap chain surface ( use the uuid ID3D11Texture2D for the result type ).
pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast< void** >( &pSurface ) );

/* The swap chain buffers are not mapable, so I need to copy it to a staging resource. */

pSurface->GetDesc( &description ); //Use ID3D11Texture2D::GetDesc to retrieve the surface description

// Patch it with a D3D11_USAGE_STAGING usage and a cpu access flag of D3D11_CPU_ACCESS_READ
description.BindFlags = 0;
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
description.Usage = D3D11_USAGE_STAGING;

// Create a temporary surface ID3D11Device::CreateTexture2D
HRESULT hr = pDevice->CreateTexture2D( &description, NULL, &pNewTexture );
if( pNewTexture )
{
// Copy to the staging surface ID3D11DeviceContext::CopyResource
pContext->CopyResource( pNewTexture, pSurface );
// Now I have a ID3D11Texture2D with the content of your swap chain buffer that allow you to use the ID3D11DeviceContext::Map API to read it on the CPU
D3D11_MAPPED_SUBRESOURCE resource;
pContext->Map( pNewTexture, D3D11CalcSubresource( 0, 0, 0), D3D11_MAP_READ, 0, &resource );

const int pitch = w << 2;
const unsigned char* source = static_cast< const unsigned char* >( resource.pData );
unsigned char* dest = static_cast< unsigned char* >(m_lpBits);
for( int i = 0; i < h; ++i )
{
memcpy( dest, source, w * 4 );
source += pitch;
dest += pitch;
}

AppendNewFrame(w, h, m_lpBits,24);

pContext->Unmap( pNewTexture, 0);
pNewTexture->Release();
}
}

最佳答案

尽管代码片段不完整,但它显示了几个潜在的问题:

  1. AppendNewFrame 行中的 Number of 24 表明您正在尝试将数据视为 24 位 RGB,而您的数据是 32 位 RGB。这种虐待与所附图片上展示的伪像相符;
  2. 俯仰/步幅被假定为默认值,而您在 D3D11_MAPPED_SUBRESOURCE 结构中有效使用了它,您应该使用它。

关于c++ - DXGI 屏幕捕获图像失真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51012364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com