好的,我想通了。可能不是最有效的,但可以完成工作。没有 memcpy,bitblt(尽管内存中的 CreateBitmap 内部可能有这些函数)。也避免了所有 DXGI 版本的废话。
D3D11_TEXTURE2D_DESC td;
m_backBufferTexture->GetDesc(&td);
td.Usage = D3D11_USAGE_STAGING;
td.BindFlags = 0;
td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
m_pDevice->CreateTexture2D( &td, NULL, &(m_pNewTexture) );
m_pContext->CopyResource(m_pNewTexture, m_backBufferTexture);
m_pNewTexture->QueryInterface(__uuidof(IDXGISurface), (void**)&m_NewTextDXGI);
DXGI_MAPPED_RECT bitmap2Dmap;
m_NewTextDXGI->Map(&bitmap2Dmap,DXGI_MAP_READ);
D2D1_PIXEL_FORMAT desc2d;
D2D1_BITMAP_PROPERTIES bmpprops;
desc2d.format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc2d.alphaMode = D2D1_ALPHA_MODE_IGNORE; // Adapt to your needs.
bmpprops.dpiX = 96.0f;
bmpprops.dpiY = 96.0f;
bmpprops.pixelFormat = desc2d;
D2D1_SIZE_U size = D2D1::SizeU(
dim.x,
dim.y
); // Adapt to your own size.
pRT->CreateBitmap(size,(void*)bitmap2Dmap.pBits,bitmap2Dmap.Pitch,bmpprops,&m_pD2DBitmap);
m_NewTextDXGI->Unmap();