Skip to main content
gamedev.net
🔒 Locked

getpixel

Started by LinX Nov 24, 2001 at 12:03 AM 2 replies 650+ views
Original Post
LinX
LinX
if i want to check the color of each pixel in a texture.. can i loop tru the texture width n height and use GetPixel ? thnx
Xeno
Xeno
it depends , if u want to check a color on DirectX's surface
you have to Lock the surface and then to read each pixel.
it looks like that: (Depends that the texture is 16 bit)

      
D3DLOCKED_RECT d3dlocked;
int wloop;
int hloop;
DWORD pixel;
DWORD Offset;


lp_d3d8_texture->LockRect(TexLevel,&d3dlocked,NULL,0);


for(wloop = 0;wloop < Width;wloop++)
{
for(hloop = 0;hloop < Height;hloop++)
{
Offset = (hloop * d3dlocked.Pitch) + (wloop * 3);
pixel = *(DWORD *)((DWORD)(lpTexBits) + Offset);

...
...
...
Do what u want to do with the pixel
...
...
...
}
}


but if u want to read a pixel from a win32api bitmap u can loop over the width and height of the bitmap and use GetPixel();

Hopes its helps.

Edited by - xeno on November 24, 2001 7:06:49 AM

Edited by - xeno on November 24, 2001 7:08:03 AM
------------------------------- Goblineye Entertainment------------------------------
LinX
LinX
thanks alot.
Xeno
Xeno
ops , in that line i made a mistake:
Offset = (hloop * d3dlocked.Pitch) + (wloop * 3);
change it to that:
Offset = (hloop * d3dlocked.Pitch) + (wloop * 2);
------------------------------- Goblineye Entertainment------------------------------

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.