Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

bitmap info

Recommended Posts

Guest Anonymous Poster
I can find the value this way:

lpDDSSurfaceMap->GetDC(&hdc);
color = GetPixel(hdc,mapx,mapy);
lpDDSSurfaceMap->ReleaseDC(hdc);

is there an easier/faster way of doing it?

Share this post


Link to post
Share on other sites
You can also do it by locking the surface, getting a pointer to the memory, then reading at the appropriate byte offset.

This way isn't more simple than going through a DC, but I believe it is faster (It avoids going through the Win API, and GetDC implicity calls Lock and ReleaseDC calls Unlock).

This is the code that could do it:

code:

char GetPixel(IDirectDrawSurface7 *lpDDSurface, DWORD x, DWORD y) {
DDSURFACEDESC2 ddsd;
ddsd.dwSize = sizeof(DDSURFACEDESC2);
if (FAILED(lpDDSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL))
; // error obtaining surface memory
char nColor = *((char *)((int)ddsd.lpSurface + x + ddsd.lPitch * y));
lpDDSurface->Unlock();
return nColor;
}


------------------
Where's my Golden Fleece?

[This message has been edited by Aeetes (edited December 20, 1999).]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I need to find out the color of a single pixel referenced by an x,y co-ordinate in a 8 bit bitmap.
Is there an easy way of doing this with directx?

Share this post


Link to post
Share on other sites
It's paletized, so you would need an unsigned char instead oa char (unsigned char = 0 - 255, char = -128 - 127). And I don't think the int is necessary.....


unsigned char nColor = *((unsigned char *)((int)ddsd.lpSurface + x + ddsd.lPitch * y));

BUT this only puts the value of that place in nColor. So...you still need to find out the RGB color (in the palette itself).

I don't know how you load your bitmap. But if you use GetDIBits (I know, I know...it's slow, but only needs to be done once). You allocate enough memory for both the BITMAPINFOHEADER (so.....the size of the BITMAPINFOHEADER AND 256 * sizeof(RGBQUAD)...
and after that call GetDIBits TWICE!!!!!!!!!!!! The second time to load the palette.

If you use this method, you will then only have to put the value of that specific pixel into the palette thingy....and you get the color........

easy huh?

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Share this post


Link to post
Share on other sites