voila ma fonction
HBITMAP rotate90(HBITMAP hbmp)
{
BITMAP bm;
GetObject((HBITMAP)hbmp, sizeof(bm), &bm);
BITMAPINFO bi,biNew;
biNew.bmiHeader.biSize = bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
biNew.bmiHeader.biHeight = bi.bmiHeader.biWidth = bm.bmWidth;
biNew.bmiHeader.biWidth = bi.bmiHeader.biHeight = bm.bmHeight;
biNew.bmiHeader.biPlanes = bi.bmiHeader.biPlanes = bm.bmPlanes;
biNew.bmiHeader.biBitCount = bi.bmiHeader.biBitCount = 24;
biNew.bmiHeader.biCompression = bi.bmiHeader.biCompression = BI_RGB;
DWORD dwWidthBytes = 4*((3*bm.bmWidth+3)/4);
DWORD dwWidthBytesNew = 4*((3*bm.bmHeight+3)/4);
LPBYTE lpBits = new BYTE[dwWidthBytes*bm.bmHeight];
LPBYTE lpBitsNew = new BYTE[dwWidthBytesNew*bm.bmWidth];
HDC hdc = GetDC(NULL);
if (hdc == NULL) { return 0; }
GetDIBits(hdc, (HBITMAP)hbmp, 0, bm.bmHeight, lpBits, &bi, DIB_RGB_COLORS);
GetDIBits(hdc, (HBITMAP)hbmp, 0, bm.bmWidth, lpBitsNew, &biNew, DIB_RGB_COLORS);
int tmp;
int tmp2;
LPDWORD lpSrc,lpDst;
for (int y = 0; y < bm.bmHeight; y++)
{
for (int x = 0; x < bm.bmWidth; x++)
{
tmp = (bm.bmHeight-y-1)*dwWidthBytes+3*x;
tmp2 = (bm.bmWidth-x-1)*dwWidthBytesNew+3*y;
lpSrc = (LPDWORD)&lpBits[tmp];
lpDst =(LPDWORD)&lpBitsNew[tmp2];
*lpDst = *lpSrc;
}
}
HBITMAP hBmpDst=CreateDIBitmap(hdc,&biNew.bmiHeader,CBM_INIT,lpBitsNew,&biNew,DIB_RGB_COLORS);
ReleaseDC(NULL, hdc);
delete lpBits;
delete lpBitsNew;
return hBmpDst;
}
Elle marche nickel sur des resolution de 33*5 ou 33*22 mais ne marche plus sur 48*16 ou 49*16 j'ai une erreur du type "debug error" et si je clique sur ignorer mon prog continu avec un bug d'affichage.
Un moyen de la faire marcher est de faire LPBYTE lpBitsNew = new BYTE[dwWidthBytesNew*bm.bmWidth+4]; mais je me retrouve toujours avec le bug d'affichage.
J'ai essayé avec plusieurs resolutions (multiple de 16 de 32) et je n'arrive meme pas a trouver un point commun logique entre celle qui marchent et celles qui marchent pas !
Quelqu'un voit un truc anormal ?