🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to get pixel color w/ a LPDIRECTDRAWSURFACE

Started by
5 comments, last by qewrty 24 years, 8 months ago
Hello!
You can just lock the surface. And then access the surface byte to byte, then you can change or get the color of the pixel.
Advertisement
Hi!

Thanks to the previous post. That lead me to the right direction. However, after spending 2 hours trying, I just couldn't figure out how to do it. However, I found in Andre Lamothe's game engine he has a locksurface function that worked for me.

Does anyone check the help files anymore? ;-)
--from the help----

IDirectDrawSurface7::GetPixelFormat
The IDirectDrawSurface7::GetPixelFormat method retrieves the color and pixel format of the surface.

HRESULT GetPixelFormat(
LPDDPIXELFORMAT lpDDPixelFormat
);

Parameters
lpDDPixelFormat
Address of the DDPIXELFORMAT structure to be filled with a detailed description of the current pixel and color space format of the surface.

He's not asking for how to get the pixel format, he's asking how to get the pixel *color*.

This can range from extremely easy to extremely difficult. If your in 8-Bit (palletized) mode then you can simply lock it and look at the pixel value you need. The color is whatever is in the pallete at the value you found. If your in 16Bit mode this can be very difficult. You have to decode the value since there are many different 16Bit color formats.

--TheGoop

Goop,
Yes, my bad. But as you said, after getting the pixel data, you need to know the format. GetPixelFormat will tell you just that.

Six

Hi!

How do you find the pixel color at a particular point on a LPDIRECTDRAWSURFACE?

Once you have the surface description from locking the surface, and assuming it is an 8 bit surface, you can get the pixel color at x,y by doing

BYTE color = (BYTE) ddsd.lpSurface[y*ddsd.lPitch+x];

This topic is closed to new replies.

Advertisement