voici comment récupérer les pixels du bitmap (on le récupère en 32 bits/pixel pour faire simple)
//************************************************// TestGetDIBits :
//
//************************************************
#include <windows.h>
#include "Resource.h"
//************************************************// WinMain :
//************************************************int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
// chargement bitmap
HBITMAP hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPRITE));
// tout d'abord on récupère des informations sur la taille du bitmap
BITMAP bmpInfo;
GetObject(hBitmap, sizeof(BITMAP), &bmpInfo);
// allocation mémoire. On va récupérer le bitmap en 32 bits/pixel pour simplifier
// comme cela, on sera sur que chaque ligne du bitmap sera codé sur un nombre
// d'octets multiple de 4. Si le bitmap n'est pas bottom-up (cas le plus fréquent)
// mais top-down, bmpInfo.bmHeight est négatif.
LPBYTE lpBits = new BYTE[4*bmpInfo.bmWidth*bmpInfo.bmHeight];
// initialisation structure BITMAPINFO
BITMAPINFO bi;
memset(&bi, 0, sizeof(BITMAPINFO));
bi.bmiHeader.biSize= sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth= bmpInfo.bmWidth;
bi.bmiHeader.biHeight= bmpInfo.bmHeight;
bi.bmiHeader.biBitCount= 32;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biCompression= BI_RGB;
// récupération pixels
HDC hdc = GetDC(NULL);
GetDIBits(hdc, hBitmap, 0, bmpInfo.bmHeight, lpBits, &bi, DIB_RGB_COLORS);
ReleaseDC(NULL, hdc);
// création d'un fichier
char szFileName[MAX_PATH];
GetModuleFileName(NULL, szFileName, MAX_PATH);
char* pEnd = strrchr(szFileName, '\\');
strcpy(pEnd, "\\Dump.txt");
HANDLE hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
// écriture des pixels à partir du haut du bitmap
char szColor[16];
DWORD dwNbBytesWritten;
for(int y = 0; y < bmpInfo.bmHeight; y++)
{
LPBYTE lpLine = lpBits+(bmpInfo.bmHeight-y-1)*4*bmpInfo.bmWidth;
for(int x = 0; x < bmpInfo.bmWidth; x++)
{
COLORREF color = *((COLORREF*)(lpLine+4*x));
wsprintf(szColor, "%08X ", color);
WriteFile(hFile, szColor, strlen(szColor), &dwNbBytesWritten, NULL);
}
WriteFile(hFile, "\r\n", 2, &dwNbBytesWritten, NULL);
}
// fermeture fichier, libération mémoire
CloseHandle(hFile);
delete[] lpBits;
return 0;
}