Can I output a one channel image acquired from camera into a winAppi window?

An 8-bit bitmap requires a color table. Since you want grayscale, you have to set up the color table to have 256 levels of gray. You’ve set the first one to black, which is correct, but you haven’t set the rest.

BITMAPINFO is actually a variably sized structure. The bmiColors field is just a placeholder for the first color in the color table. You have to allocate extra space for the entire color table and fill it out.

std::size_t size = sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
std::vector<char> buffer(size);
BITMAPINFO *dbmi = reinterpret_cast<BITMAPINFO *>(buffer.data());
ZeroMemory(dbmi, size); // probably unnecessary
dbmi->bmiHeader = bmih;
for (int i = 0; i < 256; ++i) {
  dbmi->bmiColors[i].rgbBlue = i;
  dbmi->bmiColors[i].rgbGreen = i;
  dbmi->bmiColors[i].rgbRed = i;
  dbmi->bmiColors[i].rgbReserved = 0;
}

Leave a Comment