En essayant de changer les pixels de l'image "cool.bmp" et de la dessiner dans une fenêtre modifiée. jusqu'ici tout le code s'exécute correctement mais quand je change les octets dans le tableau de pix l'image ne change pas (oui im redessinant l'écran).C++ changer les valeurs dans une image bitmap
case WM_CREATE:// runs once on creation of window
hBitmap = (HBITMAP)LoadImage(NULL, L"cool.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if(hBitmap == NULL)
::printToDebugWindow("Error: loading bitmap\n");
else
{
BYTE* b = ::getPixArray(hBitmap);
for(int i = 0; i< 1920*1080*4; i+=4) // problem!!
{
b[i] = 255;//blue
b[i+1] = 255;//green
b[i+2] = 255;//red
b[i+3] = 255;//alpha
}
// méthode pour obtenir à partir pixArray image bitmap
BYTE* getPixArray(HBITMAP hBitmap)
{
HDC hdc,hdcMem;
hdc = GetDC(NULL);
hdcMem = CreateCompatibleDC(hdc);
BITMAPINFO MyBMInfo = {0};
MyBMInfo.bmiHeader.biSize = sizeof(MyBMInfo.bmiHeader);
// Get the BITMAPINFO structure from the bitmap
if(0 == GetDIBits(hdcMem, hBitmap, 0, 0, NULL, &MyBMInfo, DIB_RGB_COLORS))
{
::printToDebugWindow("FAIL\n");
}
// create the bitmap buffer
BYTE* lpPixels = new BYTE[MyBMInfo.bmiHeader.biSizeImage];
MyBMInfo.bmiHeader.biBitCount = 32;
MyBMInfo.bmiHeader.biCompression = BI_RGB;
MyBMInfo.bmiHeader.biHeight = (MyBMInfo.bmiHeader.biHeight < 0) ? (-MyBMInfo.bmiHeader.biHeight) : (MyBMInfo.bmiHeader.biHeight);
// get the actual bitmap buffer
if(0 == GetDIBits(hdcMem, hBitmap, 0, MyBMInfo.bmiHeader.biHeight, (LPVOID)lpPixels, &MyBMInfo, DIB_RGB_COLORS))
{
::printToDebugWindow("FAIL\n");
}
return lpPixels;
}
le code ontop qui ressemble à ceci devrait changer tout le pix dans l'image au blanc? mais cela n'a aucun effet.
BYTE* b = ::getPixArray(hBitmap);
for(int i = 0; i< 1920*1080*4; i+=4) // problem!!
{
b[i] = 255;//blue
b[i+1] = 255;//green
b[i+2] = 255;//red
b[i+3] = 255;//alpha
}
oui merci! tout fonctionne! –
est là de toute façon pour obtenir une référence à la mémoire tampon réelle? –
Je ne le crois pas. MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/dd183385(v=vs.85).aspx, vérifiez votre version de Windows) peut aider. –