1
   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;

しかし、画面は空白です

4

1 に答える 1