Davros: I can't explain your problem, and I have no intention of reading through your code since I don't remember what parameters do what, and have no desire to read the documentations again But I did use GetDIBits once when I was trying to generate rotated bitmaps for my GDI graphics library, and never had any problems with it; if you care, you can sift through this and see if anything helps:
Code:
HBITMAP GFX::getRotatedBmp(HBITMAP orig, double angle, int rPointX, int rPointY)
{
if(orig == NULL)
return NULL;
HBITMAP img;
HDC dcSrc = CreateCompatibleDC(dcFront);
RECT bounds = getBmpDimensions(orig);
int width = bounds.right + 1;
int height = bounds.bottom + 1;
img = CreateCompatibleBitmap(dcFront, width, height);
BITMAPINFO bi = {0};
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
unsigned char* srcBits = new unsigned char[4 * width * height];
if(!GetDIBits(dcSrc, orig, 0, height, srcBits, &bi, DIB_RGB_COLORS))
{
delete[] srcBits;
return NULL;
}
unsigned char* destBits = new unsigned char[4 * width * height];
float sine = (float)sin(angle), cosine = (float)cos(angle); //Store result to save time
float cX = (float)rPointX, cY = (float)(bounds.bottom - rPointY); //Typecast & convert from normal coords
float tempX, tempY; //Offset on source to centre the image
tempX = (cX*(cosine-1) - cY*sine);
tempY = (cY*(cosine-1) + cX*sine);
int origX, origY;
unsigned char* destLine = destBits;
for(int y = 0; y < height; ++y)
{
for(int x = 0; x < width; ++x)
{
origX = (int)(((float)x + tempX)*cosine + ((float)y + tempY)*sine);
origY = (int)(((float)y + tempY)*cosine - ((float)x + tempX)*sine);
if(origX >= 0 && origY >= 0 && origX < bounds.right && origY < bounds.bottom)
{
destLine[(x << 2) ] = srcBits[((origX + width*origY) << 2) ];
destLine[(x << 2) + 1] = srcBits[((origX + width*origY) << 2) + 1];
destLine[(x << 2) + 2] = srcBits[((origX + width*origY) << 2) + 2];
}
else
{
destLine[(x << 2) ] = 0;
destLine[(x << 2) + 1] = 0;
destLine[(x << 2) + 2] = 0;
}
}
destLine += (width << 2);
}
SetDIBits(dcSrc, img, 0, height, destBits, &bi, DIB_RGB_COLORS);
DeleteDC(dcSrc);
delete[] srcBits;
delete[] destBits;
return img;
}