LPDIRECT3DSURFACE9 pSurface = NULL; HRESULT hr = pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface); if (FAILED(hr)) { return; } D3DLOCKED_RECT lockedRect; pSurface->LockRect(&lockedRect, NULL, D3DLOCK_READONLY); BYTE* pBits = (BYTE*)lockedRect.pBits; // Do something with pBits... pSurface->UnlockRect();
HRESULT hr = D3DXCreateTextureFromFile(pd3dDevice, "texture.bmp", &pTexture); if (FAILED(hr)) { return; } LPDIRECT3DSURFACE9 pSurface = NULL; pTexture->GetSurfaceLevel(0, &pSurface); D3DLOCKED_RECT lockedRect; pSurface->LockRect(&lockedRect, NULL, 0); BYTE* pBits = (BYTE*)lockedRect.pBits; // Do something with pBits... pSurface->UnlockRect(); pSurface->Release();This code loads a texture from a file and obtains its surface. The surface is locked for read-write access and the pointer to the locked memory is obtained through the `pBits` variable. After the surface is processed, it is unlocked and released. Package library: d3dx9.lib