首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DXGI截屏失真图像

DXGI截屏失真图像
EN

Stack Overflow用户
提问于 2018-06-25 01:32:47
回答 1查看 352关注 0票数 1

不仅fps从60下降到20-21,而且图像看起来也像这样失真。第二张图片是它应该看起来的样子

What it looks like What it should look like

代码语言:javascript
复制
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();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-26 18:25:48

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

  1. AppendNewFrame行中的数字为24表明您正在尝试将数据视为24位RGB,而您的数据是32位RGB。这种不当处理与附加的images;
  2. Pitch/stride上显示的工件相匹配,被视为假定的默认值,而您在D3D11_MAPPED_SUBRESOURCE structure中具有有效使用的工件,并且您应该使用它。
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51012364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档