void drawImage(HWND &hWnd,HBITMAP &hBitmap)
{
PAINTSTRUCT ps;
HDC hdc;
BITMAP bitmap;
HDC hdcMem;
HGDIOBJ oldBitmap;
RECT rec;
::GetClientRect(hWnd,&rec);
hdc = BeginPaint(hWnd, &ps);
hdcMem = CreateCompatibleDC(hdc);
oldBitmap = SelectObject(hdcMem, hBitmap);
GetObject(hBitmap, sizeof(bitmap), &bitmap);
int* x = (int*)bitmap.bmBits; ?? problem
x[0] = 0xff00ff;
//draw image so it fits entire window
StretchBlt(hdc, 0, 0, rec.right, rec.bottom, hdcMem, 0, 0,bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
SelectObject(hdcMem, oldBitmap);
DeleteDC(hdcMem);
EndPaint(hWnd, &ps);
}
在上面的代码中,我有一个简单的窗口,我在上面绘制了一个 BMP 图像。问题是我不知道如何获取对内部 int 数组的引用。我希望能够随意更改和操纵图像中的像素。
我试过:
int* x = (int*)bitmap.bmBits;
x[0] = 0xff00ff;
但屏幕是空白的