on 5/30/04 9:00 PM, Brad Hutchings at brad at componentx dot com wrote:
> this code snippet:
>
> #if CX_GRAPHICS_WIN32
> BITMAPINFO bmi;
> bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> bmi.bmiHeader.biWidth = width;
> bmi.bmiHeader.biHeight = height;
> bmi.bmiHeader.biPlanes = 1;
> bmi.bmiHeader.biBitCount = depth;
> bmi.bmiHeader.biCompression = BI_RGB;
> bmi.bmiHeader.biSizeImage =
> ((bmi.bmiHeader.biWidth*bmi.bmiHeader.biBitCount/
> 8+3)&0xFFFFFFFC)*bmi.bmiHeader.biHeight;
> bmi.bmiHeader.biXPelsPerMeter = 2835; // 72 dpi
> bmi.bmiHeader.biYPelsPerMeter = 2835; // 72 dpi
> bmi.bmiHeader.biClrUsed = 0;
> bmi.bmiHeader.biClrImportant = 0;
>
> HDC dc = CreateCompatibleDC(NULL);
> debug_message("created dc");
>
> void* bits;
> HBITMAP hbm = CreateDIBSection(dc, &bmi, DIB_RGB_COLORS, &bits, 0, 0);
> debug_message("created dib");
>
> _fPicture = REALBuildPictureFromDIB(hbm, true);
> debug_message("created _fPicture");
> ...
COuld be a memset problem, you don't use, or a selectObject or ...
Here are code snippets that work for me (did not try to create a picture of
it, but drawing in the memoryDC is ok:
HDC _CreateMemoryDC(HWND hwnd)
{
HDC hMemDC, hDC;
hDC = GetDC(hwnd);
if (hDC) {
hMemDC = CreateCompatibleDC(hDC);
SetMapMode(hMemDC, GetMapMode(hDC));
ReleaseDC(hwnd, hDC);
return hMemDC;
}
return NULL;
}
WORD _GetDCBitDepth(HDC hDC)
{
return(GetDeviceCaps( hDC, BITSPIXEL));
}
// a struct large enough to hold the largest bitmapinfo ...
struct BITMAPINFO_256 {
BITMAPINFOHEADER bmiHeader;
long bmiColors[256];
};
typedef struct BITMAPINFO_256 BITMAPINFO_256;
BITMAPINFO_256 bitmapInfo;
void *baseaddr;
// create a DIB section
memset(&bitmapInfo, 0, sizeof(bitmapInfo));
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biHeight = -1 * height; // top down dib
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = depth;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = 0;
bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
bitmapInfo.bmiHeader.biClrUsed = 0;
bitmapInfo.bmiHeader.biClrImportant = 0;
bitmapInfo.bmiColors[0] = 0;
bitmapInfo.bmiColors[1] = 0;
bitmapInfo.bmiColors[2] = 0;
bitmapInfo.bmiColors[3] = 0;
data->hBitmap = CreateDIBSection(hDC, (BITMAPINFO *)&bitmapInfo,
DIB_RGB_COLORS, &baseaddr, nil, 0);
SelectObject(data->hMemDC, data->hBitmap);
ReleaseDC(owner, hDC);
HTH,
Alfred
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|