I'm using Desktop Duplication API. After I call AcquireNextFrame I get a Texture2D from the API in Full HD resolution. I would like to resize it and make it smaller (like 1280x720 for example) before drawing it. Here is my code :
if (texture2D != NULL)
{
D3D11_TEXTURE2D_DESC description;
texture2D->GetDesc(&description);
description.BindFlags = 0;
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
description.Usage = D3D11_USAGE_STAGING;
description.MiscFlags = 0;
description.Width = 1280;
description.Height = 720;
ID3D11Texture2D *texTemp = NULL;
HRESULT hr = m_Device->CreateTexture2D(&description, NULL, &texTemp);
if (FAILED(hr))
{
if (texTemp)
{
texTemp->Release();
texTemp = NULL;
}
return NULL;
}
m_DeviceContext->CopyResource(texTemp, texture2D);
D3D11_MAPPED_SUBRESOURCE mapped;
hr = m_DeviceContext->Map(texTemp, 0, D3D11_MAP_READ, 0, &mapped);
if (FAILED(hr))
{
texTemp->Release();
texTemp = NULL;
return NULL;
}
unsigned char *source = static_cast<unsigned char*>(mapped.pData);
//here the source has no values. If I remove description.Width = 1280;
//description.Height = 720; I get values
}
Can someone help ? Thanks
I'm using Desktop Duplication API. After I call AcquireNextFrame I get a Texture2D from the API in Full HD resolution. I would like to resize it and make it smaller (like 1280x720 for example) before drawing it. Here is my code :
if (texture2D != NULL)
{
D3D11_TEXTURE2D_DESC description;
texture2D->GetDesc(&description);
description.BindFlags = 0;
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
description.Usage = D3D11_USAGE_STAGING;
description.MiscFlags = 0;
description.Width = 1280;
description.Height = 720;
ID3D11Texture2D *texTemp = NULL;
HRESULT hr = m_Device->CreateTexture2D(&description, NULL, &texTemp);
if (FAILED(hr))
{
if (texTemp)
{
texTemp->Release();
texTemp = NULL;
}
return NULL;
}
m_DeviceContext->CopyResource(texTemp, texture2D);
D3D11_MAPPED_SUBRESOURCE mapped;
hr = m_DeviceContext->Map(texTemp, 0, D3D11_MAP_READ, 0, &mapped);
if (FAILED(hr))
{
texTemp->Release();
texTemp = NULL;
return NULL;
}
unsigned char *source = static_cast<unsigned char*>(mapped.pData);
//here the source has no values. If I remove description.Width = 1280;
//description.Height = 720; I get values
}
Can someone help ? Thanks