Some time ago I asked a question about saving hwnd into ppm file. Thanks to a stackoverflow user I have solved my issue. Iy's work correctly but I still have a problem: the red and blue color are inverted.

the code and my previous question where here: hwnd to ppm issue

Here is the bitmap info data:

bi.biSize = sizeof(BITMAPINFOHEADER);    
bi.biWidth = w;    
bi.biHeight = -h;  
bi.biPlanes = 1;    
bi.biBitCount = 24;    
bi.biCompression = BI_RGB;    

bi.biSizeImage = 0;  
bi.biXPelsPerMeter = 0;    
bi.biYPelsPerMeter = 0;    
bi.biClrUsed = 0;    
bi.biClrImportant = 0;

I googled and it seems the problem is BI_RGB, and I should use BI_BITFIELDS ... but I didn't find documentation on how to use it. And I really don't want to read all data pixel by pixel in order to revert blue and red color. Is there any way to get it done without doing it pixel by pixel ?

thanks in advance for your help

有帮助吗?

解决方案

In a 24bpp BMP, the pixels store their colors in least endian order. Blue is first, red is last. In PPM red is first, blue is last. Which largely explains why it is such an obscure image format on Windows. You'll have to swap the storage order yourself.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top