6
我讀過另一個線程,我可以用Texture.Lock/Unlock讀取一個像素,但是我需要在讀取它們之後將像素寫回紋理,這是我迄今爲止的代碼單個像素的DirectX設置顏色
unsigned int readPixel(LPDIRECT3DTEXTURE9 pTexture, UINT x, UINT y)
{
D3DLOCKED_RECT rect;
ZeroMemory(&rect, sizeof(D3DLOCKED_RECT));
pTexture->LockRect(0, &rect, NULL, D3DLOCK_READONLY);
unsigned char *bits = (unsigned char *)rect.pBits;
unsigned int pixel = (unsigned int)&bits[rect.Pitch * y + 4 * x];
pTexture->UnlockRect(0);
return pixel;
}
所以我的問題是:
- How to write the pixels back to the texture?
- How to get the ARGB values from this unsigned int?
((BYTE)X >> 8/16/24)我沒有工作(從函數返回值是688)
出於好奇,你爲什麼需要這樣做? – tbridge 2011-03-20 23:28:48
你應該知道這種鎖定的性能只是蟑螂級別。 (在2002年,我的測試表明它的性能是0.5 FPS,今天可能會更快,但是你仍然在爲自己做這種事情而癱瘓。) – 2013-07-19 03:40:23