3

I'm using AcquireNextFrame to make a screenshot of my desktop. Is it possible to set a dimension of the output image I want on the setup ? I saw on the documentation this function IDXGIOutput::SetDisplaySurface that could help. Here is my code :

//Here I init a output texture with less resolution 
    D3D11_TEXTURE2D_DESC desc;
    desc.Width = 1280;
    desc.Height = 720;
    desc.MipLevels = desc.ArraySize = 1;
    desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    desc.SampleDesc.Count = 1;
    desc.Usage = D3D11_USAGE_DYNAMIC;
    desc.BindFlags = 0;
    desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    desc.MiscFlags = 0;

    ID3D11Texture2D *pTexture = NULL;
    gDevice->CreateTexture2D(&desc, NULL, &pTexture);
    IDXGISurface *surface = nullptr;
    hr = gDevice->QueryInterface(__uuidof(IDXGISurface), reinterpret_cast<void **>(&pTexture));
    if (FAILED(hr))
        return;
    // Here I should make lDxgiOutput->setDisplaySurface(surface)
    hr = lDxgiOutput->GetDesc(&gOutputDesc);
    if (FAILED(hr))
        return;
    IDXGIOutput1 *lDxgiOutput1 = nullptr;
    hr = lDxgiOutput->QueryInterface(IID_PPV_ARGS(&lDxgiOutput1));
    if (FAILED(hr))
        return;
    lDxgiOutput->Release();
    hr = lDxgiOutput1->DuplicateOutput(gDevice, &gDeskDupl);
    if (FAILED(hr))
        return;

My screen is 1920x1080 and I would like to get image in 1280x720 for example. I'm getting an error on queryinterface function. Can someone tell me what I'm missing ? Or is there any solution to customize the resolution easier ? Thanks

4

1 回答 1

1

桌面复制 API 以最少的开销为您提供桌面副本作为纹理。也就是说,不包括缩放。您可以根据需要抓取帧并按比例缩小它们,但这不是 Desktop Duplication 所做的或期望为您做的。

这个问题提出了几种方法(这个问题也与桌面复制有关):

此外,您可以使用 Media Foundation 的Video Processor MFT,如果您不使用 Media Foundation ,它有点不灵活并且可能具有不方便的外形尺寸,但使用 Direct3D 11 以有效的方式正确设置比例性能方面。

另请参阅有关启用 GPU 的缩放的另一个相关 API:

于 2017-06-03T17:45:30.790 回答