简体   繁体   中英

How to read an 8bit bitmap's pixel colour and postion from byte array

I currently have my 8bit bitmap's pixel data stored in an array of bytes: BYTE* pixelData .

How would I now go about coding my own function to return a pixel's colour by it's position? I've done a fair amount of searching and haven't found anything that covers this using C++.

BYTE GetPixelColor(BYTE* src, int x, int y, int srcWidth)
{
    return src[y * srcWidth + x];
}

...
//suppose you have a 800 x 600 bmp, to get the color for pixel at x 30, y 200
BYTE color = GetPixelColor(src, 30, 200, 800);

You can't, not enough data. Almost all 8bpp pixel formats are indexed formats. They use a color table that stores the actual RGB color, the byte at the pixel location is an index into that table. The table contains 256 entries.

You'll also need a pointer to the color table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM