Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


bitmap info


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 20 December 1999 - 10:42 PM

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?

Sponsor:

#2 Gromit   Members   -  Reputation: 144

Like
Likes
Like

Posted 20 December 1999 - 03:57 AM

The answer is yes. A very easy way I might add. I might even go as far as to say... simple. Very easy indeed.

Do you want to know how?


#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 20 December 1999 - 05:00 AM

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?


#4 Aeetes   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 December 1999 - 06:49 AM

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).]


#5 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 December 1999 - 10:42 PM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS