Jesus Army Allez voir là bas si j'y suis | Je la lis avec cette fonction : (depuis une ressource)
Code :
- //Là c'est la methode appellée par le constructeur
- BOOL Bitmap::Create(HDC hDC, UINT uiResID, HINSTANCE hInstance)
- {
- // Free any previous DIB info
- Free();
- // Find the bitmap resource
- HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(uiResID), RT_BITMAP);
- if (hResInfo == NULL)
- return FALSE;
- // Load the bitmap resource
- HGLOBAL hMemBitmap = LoadResource(hInstance, hResInfo);
- if (hMemBitmap == NULL)
- return FALSE;
- // Lock the resource and access the entire bitmap image
- PBYTE pBitmapImage = (BYTE*)LockResource(hMemBitmap);
- if (pBitmapImage == NULL)
- {
- FreeResource(hMemBitmap);
- return FALSE;
- }
- // Store the width and height of the bitmap
- BITMAPINFO* pBitmapInfo = (BITMAPINFO*)pBitmapImage;
- m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
- m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;
- // Get a handle to the bitmap and copy the image bits
- PBYTE pBitmapBits;
- m_hBitmap = CreateDIBSection(hDC, pBitmapInfo, DIB_RGB_COLORS,
- (PVOID*)&pBitmapBits, NULL, 0);
- if ((m_hBitmap != NULL) && (pBitmapBits != NULL))
- {
- const PBYTE pTempBits = pBitmapImage + pBitmapInfo->bmiHeader.biSize +
- pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD);
- CopyMemory(pBitmapBits, pTempBits, pBitmapInfo->bmiHeader.biSizeImage);
- // Unlock and free the bitmap graphics object
- UnlockResource(hMemBitmap);
- FreeResource(hMemBitmap);
- return TRUE;
- }
- // Something went wrong, so cleanup everything
- UnlockResource(hMemBitmap);
- FreeResource(hMemBitmap);
- Free();
- return FALSE;
- }
|
Et ensuite je la dessine avec celle ci :
Code :
- void Bitmap::Draw(HDC hDC, int x, int y, BOOL bTrans, COLORREF crTransColor)
- {
- if (m_hBitmap != NULL)
- {
- // Create a memory device context for the bitmap
- HDC hMemDC = CreateCompatibleDC(hDC);
- // Select the bitmap into the device context
- HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap);
- // Draw the bitmap to the destination device context
- if (bTrans)
- TransparentBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0,
- GetWidth(), GetHeight(), crTransColor);
- else
- BitBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0, SRCCOPY);
- // Restore and delete the memory device context
- SelectObject(hMemDC, hOldBitmap);
- DeleteDC(hMemDC);
- }
- }
|
Et ca marche très bien pour toutes les zimages bmp 8 bits de windows, mais pas les mienne... Et il suffit par exemple que j'ouvre la bitmap avec paint, que je fasse une modif d'un pixel et que je save et hop ca ne marche plus... ![:/ :/](https://forum-images.hardware.fr/icones/ohwell.gif) |