Have you tried......
CreateCompatibleDC()
CreateCompatibleBitmap() // the same size as your image
then SetDIBits() to copy your image to the BMP
In the paint handler BitBlt() your image to the HDC returned by BeginPaint()
I don't think it will work (at differing screen colour depths).
these pieces are cut from a screen capture function of mine (where I have the image as a bmp and I am copying it)
You would need to SetDIBits() to copy your array to the bmp (ie transfer image to new blank bmp)
In your case cClrBits = 8
Code:
PBITMAPINFO pbmi;
pbmi = (PBITMAPINFO) GlobalAlloc(LPTR, sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*(1<< cClrBits));
//error check removed
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
if (cClrBits < 24)
pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
// If the bitmap is not compressed, set the BI_RGB flag.
pbmi->bmiHeader.biCompression = BI_RGB;
// For Windows NT, the width must be DWORD aligned unless
// the bitmap is RLE compressed.
// For Windows 95/98/Me, the width must be WORD aligned unless the
// bitmap is RLE compressed.
pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
* pbmi->bmiHeader.biHeight;
// Set biClrImportant to 0, indicating that all of the
// device colors are important.
pbmi->bmiHeader.biClrImportant = 0;
//next function
//set header
BITMAPFILEHEADER hdr; // bitmap file-header
hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
// Compute the size of the entire file.
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage);
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;