自定义输出分辨率DuplicateOutput DXGI [英] Custom output resolution DuplicateOutput DXGI

查看:513
本文介绍了自定义输出分辨率DuplicateOutput DXGI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AcquireNextFrame制作我的桌面的屏幕截图.是否可以在设置中设置我想要的输出图像的尺寸? 我在文档中看到此功能IDXGIOutput::SetDisplaySurface可能会有所帮助. 这是我的代码:

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;

我的屏幕是1920x1080,例如,我想以1280x720的分辨率获取图像. 我在queryinterface函数上遇到错误. 有人可以告诉我我想念什么吗?还是有任何解决方案可以更轻松地自定义分辨率? 谢谢

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

推荐答案

桌面复制API可以以最少的开销为您提供作为纹理的桌面副本.即,不包括缩放.您可以根据需要抓取帧并将其按比例缩小,但这不是桌面复制"为您做或不会为您做的.

Desktop Duplication API gets you a copy of desktop as a texture with least overhead. That is, no scaling is included. You can grab frames and scale them down as you wish, but this is not what Desktop Duplication does or expected to do for you.

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

This question suggests a few ways (and the question is also related to Desktop Duplication):

此外,您可以使用Media Foundation的视频处理器MFT ,如果您不使用Media Foundation,而是使用Direct3D 11以高效的方式正确设置缩放比例,则这有点不灵活,并且可能会带来不便的形状.

Additionally, you can use Media Foundation's Video Processor MFT, which is somewhat inflexible and has a possibly inconvenient form factor if you don't use Media Foundation otherwise, but properly set up scales using Direct3D 11 in efficient way performance-wise.

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

See also on another related API for GPU-enabled scaling:

这篇关于自定义输出分辨率DuplicateOutput DXGI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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