Getting a Pixel's Color Value...
Hello again...
I was trying to make a program that would load a 256 color grayscale image and convert it to hight information, and I was wondering wether there was any DirectDraw routine that would be able to help me out.
I found alot on ploting pixels, but not much on getting pixel information.
Thank you for Time
-Doddler
You would have to get a pointer to the actual image data by locking the DDSurface and the read the value of the pixel at the coordinate you''re interested in.
BYTE Height = ImageBuffer[x + y*pitch];
BYTE Height = ImageBuffer[x + y*pitch];
What format is your image in? It''s probably not necessary to load the whole thing onto a surface first. Ex: If it''s a grey-scale bitmap, you can just read the bitmap area with simple pointer arithmetic.
Ok... Thanks for the input. I''ll try out what you said. The image is stored in a bmp (I might change this later, but bitmaps are easier for now). Um, SiCrane, could you give me an example of how this is done? I''ve learned all my knowledge of C++ by reading examples, and, well, while I can do certain things well, some things I''m unsure of (my income really doesn''t allow me to spend money on books). Anyways, thanks for the help.
-Doddler
-Doddler
Well, off the top of my, in pseudo-codeish it looks like this:
Is that enough to get you started, or do you need more accurate code?
FILE * fp = fopen("file.bmp", "rb");char * buffer = new char[(size-of-file)];// read the whole file into bufferBITMAPFILEHEADER * ptr1 = (BITMAPFILEHEADER *)buffer;BITMAPINFOHEADER * ptr2 = (BITMAPINFOHEADER *)(buffer + sizeof(BITMAPFILEHEADER));char * ptr3 = buffer + sizeof(BITMAPFILEHEADER) + ptr1->bfOffBits;int width = ptr2->biWidth;if (width % 4 == 1) width += 3;else if (width % 4 == 2) width += 2;else if (width % 4 == 3) width += 1;value_at_x_y = *ptr3[x + width * y];
Is that enough to get you started, or do you need more accurate code?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement