Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetDIBits on Windows CE

660 views
Skip to first unread message

Michael Schwarz

unread,
May 2, 2002, 9:38:16 AM5/2/02
to
Hello,

I had already posted some questions about writing bitmaps on Pocket
PCs. Now I am still on a problem I could not find the answer. I always
get only a 240x340 pixeled black bitmap. That's beacuse of the missing
GetDIBits I have put away. But how can I do this on Pocket PCs???

Thanks a lot for your help, I tried this in VC++ and it works fine, I
think the only problem is really the GetDIBits...

Michael

<Code>

// prepare DCs, bitmaps,..
HDC hScreenDC = GetWindowDC(0);
HDC hmemDC = CreateCompatibleDC(hScreenDC);
int ScreenWidth = GetDeviceCaps(hScreenDC, HORZRES);
int ScreenHeight = GetDeviceCaps(hScreenDC, VERTRES);
HBITMAP hmemBM = CreateCompatibleBitmap(hScreenDC, ScreenWidth,
ScreenHeight);
SelectObject(hmemDC, hmemBM);

// copy screen to memory DC
BitBlt(hmemDC, 0, 0, ScreenWidth, ScreenHeight, hScreenDC, 0, 0,
SRCCOPY);

CreateBMPFile(0, _T("\\xxx2.bmp"),CreateBitmapInfoStruct(0,
hmemBM),hmemBM, hmemDC);

DeleteObject(hmemBM);
DeleteDC(hmemDC);
ReleaseDC(0, hScreenDC);


PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp)
{
...
}

void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,
HBITMAP hBMP, HDC hDC)
{
HANDLE hf; // file handle
BITMAPFILEHEADER hdr; // bitmap file-header
PBITMAPINFOHEADER pbih; // bitmap info-header
LPBYTE lpBits; // memory pointer
DWORD dwTotal; // total count of bytes
DWORD cb; // incremental count of bytes
BYTE *hp; // byte pointer
DWORD dwTmp;

pbih = (PBITMAPINFOHEADER) pbi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

//Windows CE does not support GetDIBits???
//GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,
DIB_RGB_COLORS);

hf = CreateFile(pszFile,
GENERIC_READ | GENERIC_WRITE,
(DWORD) 0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);

hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"

hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof(RGBQUAD) + pbih->biSizeImage);

hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;

hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof (RGBQUAD);

WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD)
&dwTmp, NULL);
WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) +
pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, ( NULL));

dwTotal = cb = pbih->biSizeImage;

hp = lpBits;

WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL);

CloseHandle(hf);
GlobalFree((HGLOBAL)lpBits);
}

</Code>

Yaroslav Goncharov

unread,
May 2, 2002, 4:09:12 PM5/2/02
to
Hi

GetDIBits is not supported under Windows CE. Perhaps the following article
will help you
http://www.pocketpcdn.com/qa/bitmap_bits.html

--
Yaroslav Goncharov
Smartphone Developer Network
www.smartphonedn.com


"Michael Schwarz" <goo...@schwarz-interactive.de> wrote in message
news:42d12a77.02050...@posting.google.com...

> file://Windows CE does not support GetDIBits???
> file://GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,

Brian Burgess

unread,
May 2, 2002, 10:26:16 PM5/2/02
to
Hi Michael,

Here is a sample that creates a file from 'CreateDIBSection' instead of
'CreateCompatibleBitmap'... It sets the color depth down to 2 colors
however.. maybe it will be helpful to you to figure it out..:


BOOL CSigCapDlg::createBitmapFile(LPCTSTR szFileName)
{
//BITMAP bmp;
PBITMAPINFO pbmi = NULL;
WORD cClrBits = 1;
int nColors = 2;
RGBQUAD Colors2[] =
{
{0x00, 0x00, 0x00, 0x00},
{0xFF, 0xFF, 0xFF, 0x00}
};

int nWidth = (int) spSignatureBox->GetWidth();
int nHeight = (int) spSignatureBox->GetHeight();

int nBytesPerLine = ((nWidth * cClrBits + 31)&(~31)) / 8;
DWORD dwBitmapInfoSize = sizeof(BITMAPINFOHEADER) + nColors *
sizeof(RGBQUAD);
DWORD dwFileHeaderSize = dwBitmapInfoSize + sizeof(BITMAPFILEHEADER);

BITMAPFILEHEADER bmpfhdr;
BYTE* lpBuf = new BYTE[dwBitmapInfoSize];
BITMAPINFO* lpbi = (BITMAPINFO*) lpBuf;
BITMAPINFOHEADER& bih = lpbi->bmiHeader;

HBITMAP hBmp;
LPVOID ppvBits;

memset(&bih, 0, sizeof(BITMAPINFOHEADER));

// Initialize the fields in the BITMAPINFO structure.
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biWidth = nWidth;
bih.biHeight = nHeight;
bih.biPlanes = 1;
bih.biBitCount = 1;
bih.biCompression = BI_RGB;
bih.biSizeImage = 0;

RGBQUAD* pColors = &Colors2[0];
memcpy(&lpbi->bmiColors[0], &pColors[0], sizeof(RGBQUAD));
memcpy(&lpbi->bmiColors[1], &pColors[1], sizeof(RGBQUAD));

bmpfhdr.bfType = 0x4d42; //'BM' file type
bmpfhdr.bfSize = dwFileHeaderSize + (nBytesPerLine * nHeight);
bmpfhdr.bfReserved1 = 0;
bmpfhdr.bfReserved2 = 0;
bmpfhdr.bfOffBits = dwFileHeaderSize;


//get a memory device context(DC) first...
m_hSignatureBoxDC = ::GetDC(m_hSignatureBox);

//then our DIBSection using the structure manually created from above...
m_hSignatureBoxBMP = CreateDIBSection(m_hSignatureBoxDC, lpbi,
DIB_RGB_COLORS, &ppvBits, NULL, 0);
m_hMemDC = CreateCompatibleDC(m_hSignatureBoxDC);

hBmp = (HBITMAP) SelectObject(m_hMemDC, m_hSignatureBoxBMP);
BitBlt(m_hMemDC,0,0,nWidth,nHeight,m_hSignatureBoxDC,0,0,SRCCOPY);
SelectObject(m_hMemDC, hBmp);

DWORD dwNumBytes;

HANDLE hFile = CreateFile(szFileName,


GENERIC_WRITE,
(DWORD) 0, NULL, CREATE_ALWAYS,

FILE_ATTRIBUTE_NORMAL, NULL);

if (hFile == INVALID_HANDLE_VALUE)
return FALSE;

WriteFile(hFile, &bmpfhdr, sizeof(bmpfhdr), &dwNumBytes, NULL); // Write
the file header
WriteFile(hFile, lpbi, dwBitmapInfoSize, &dwNumBytes, NULL); // Write the
DIB header
WriteFile(hFile, ppvBits, nBytesPerLine * nHeight, &dwNumBytes, NULL); //
Write DIB bits
CloseHandle(hFile);

delete lpBuf;

DeleteObject(hBmp);
DeleteDC(m_hMemDC);
::ReleaseDC(m_hSignatureBox, m_hSignatureBoxDC);


return TRUE;
}


"Michael Schwarz" <goo...@schwarz-interactive.de> wrote in message
news:42d12a77.02050...@posting.google.com...

Michael Schwarz

unread,
May 3, 2002, 5:47:21 AM5/3/02
to
Hi Brian,

"Brian Burgess" <bburg...@hotmail.com> wrote in message news:<##Gylnk8BHA.372@tkmsftngp03>...


> Hi Michael,
>
> Here is a sample that creates a file from 'CreateDIBSection' instead of
> 'CreateCompatibleBitmap'... It sets the color depth down to 2 colors
> however.. maybe it will be helpful to you to figure it out..:
>
>

...

thank you for your fast answer. I tried now this code to replace the
GetDIBits function that is not supported by Windows CE:

<Code>

HBITMAP m_hSignatureBoxBMP = CreateDIBSection(hDC, pbi,
DIB_RGB_COLORS, (void**)&lpBits, NULL, 0);
HDC m_hMemDC = CreateCompatibleDC(hDC);
SelectObject(m_hMemDC, m_hSignatureBoxBMP);
BitBlt(m_hMemDC,0,0,240,320,hDC,0,0,SRCCOPY);
DeleteDC(m_hMemDC);

</Code>

Now, when I test this function in the Pocket PC Emulator on my PC I
get a nice bitmap about 300kB. When I compile the project for ARM
processors and start the program on my iPAQ I get always a 256kB image
that could not be opend. Is there a difference between the emualtion
on the real Pocket PC? Or do I have still some mistakes. I am a VB
developer trying to start VC++!!! ;)

Michael

Brian Burgess

unread,
May 3, 2002, 11:40:51 PM5/3/02
to
Hi Michael,

There are some differences yes, the emulator will execute the relative
Host Windows (whatever OS you have) API functions such as the
'CreateDIBSection'. I'm not sure of the detailed differences in these
functions however...

Perhaps a Microsoft MVP guru will answer .. :-)

0 new messages