16,472
社区成员
发帖
与我相关
我的任务
分享
int width = FB_X; // 1000
int height = FB_Y; // 1000
BITMAPINFO lpbmi;
lpbmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpbmi.bmiHeader.biWidth = FB_X;
lpbmi.bmiHeader.biHeight = FB_Y;
lpbmi.bmiHeader.biPlanes = 1;
lpbmi.bmiHeader.biBitCount = 32;
lpbmi.bmiHeader.biCompression = BI_RGB;
DWORD* pBits = NULL;
HBITMAP hMemBmp = ::CreateDIBSection(NULL, &lpbmi, DIB_RGB_COLORS, (void **)&pBits, NULL, 0);
for (x=0;x<FB_X;x++) {
for (y=0;y<FB_Y;y++,lp++) {
if ( color != -1 ) {
int y0 = FB_Y - y - 1;
//SetPixelV(hdc, x, y, color);
pBits[(y0 * width) + x] = color;
//SetPixelV(hdc, x, y0, pBits[(y0 * width) + x]);
}
}
}
unsigned long **FBuf; // 1000 * 1000, 存储color值得既定数组。
// ......
int width = 1000;
int height = 1000;
BITMAPINFO lpbmi;
lpbmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpbmi.bmiHeader.biWidth = width;
lpbmi.bmiHeader.biHeight = height;
lpbmi.bmiHeader.biPlanes = 1;
lpbmi.bmiHeader.biBitCount = 32;
lpbmi.bmiHeader.biCompression = BI_RGB;
BYTE* pBits = NULL; // 注意此处为BYTE,下面计算的时候应该乘以(biBitCount / 8) = 4;
HBITMAP hBtmp= ::CreateDIBSection(NULL, &lpbmi, DIB_RGB_COLORS, (void **)&pBits, NULL, 0);
HBITMAP hOldBmp = ::SelectObject(hdc, hBtmp);
for (x = 0; x < 1000; x++) {
lp = FBuf[x];
for (y = 0; y < 1000; y++, lp++) {
// 【1】原先的方式
// int y0 = FB_Y - y - 1;
// SetPixelV(hdc, x, y0, (*lp));
// 【2】错误方式
// pBits[(y * width * 4) + x * 4 ] = *lp;
// 【3】最终正确的方案
pBits[(y * width * 4) + x * 4 + 2] = GetRValue( (*lp) ); // r
pBits[(y * width * 4) + x * 4 + 1] = GetGValue( (*lp) ); // g
pBits[(y * width * 4) + x * 4 + 0] = GetBValue( (*lp) ); // b
}
}