• 9
• 16
• 15
• 12
• 9

# What is the formula for reading a pixel? (eg. using pitch and format?)

This topic is 3873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Let's say I have a D3DLOCKED_RECT record and I want to read a single pixel. What is the formula? The D3DLOCKED_RECT contains a Pitch variable and a pointer to a pixel structure. I'm pretty sure I need to multiply the (x, y) by the pitch but I'm not sure. I'm using Delphi, so any generic formula would be very helpful (as opposed to a C++ pointer-math formula). Also, if my back-buffer format is XRGB, then is it stored the opposite way in memory? (eg. BGRX) Thanks for your help!

##### Share on other sites
Ahhh, OK. I see what you're saying.

I'm having another strange problem though.

Every _other_ click I get real data or all zeros.

For example,

The first call to GetPixel(0, 0) shows me ARGB(0, 100, 200, 50) but the second click to GetPixel(0, 0) shows me ARGB(0, 0, 0, 0) and then the third call goes back to (0, 100, 200, 50), and the forth call goes to (0, 0, 0, 0).

It's alternating between the real values and all zeros.

I'm getting the backbuffer like this:

res := Devices[0].Dev9.GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, Surface);

(inside my OnClick on my Delphi form event)

##### Share on other sites
Maybe the format of the surface is not ARGB. You should check the format with IDirect3DSurface9::GetDesc().

Sorry for the late reply.