|
I just CDIBSectionLite class to implement dib draw in my PPC2002 app.
but i found it is fail to CreateDIBSection , same code is work in PC
platfrom.
// just create a 160*120 rect, and fill with black color
iWidthIn = 160;
iHeightIn = 120;
int nScanWidth = CDIBSectionLite::BytesPerLine(m_iWidthIn, 32);
pBaseBits = new BYTE[nScanWidth * m_iHeightIn];
memset(pBaseBits, 0x00, sizeof(BYTE) * nScanWidth * m_iHeightIn);
// fill the struct of bitmap info
BITMAPINFO bmi;
BITMAPINFOHEADER bmiheader=
sizeof(BITMAPINFOHEADER), // biSize
m_iWidthIn, // biWidth;
m_iHeightIn, // biHeight;
1, // biPlanes;
32, // biBitCount
BI_RGB, // biCompression;
nScanWidth * m_iHeightIn, // biSizeImage;
0, // biXPelsPerMeter;
0, // biYPelsPerMeter;
0, // biClrUsed;
0 // biClrImportant;
};
memset(&bmi, 0x00, sizeof(BITMAPINFO));
bmi.bmiHeader = bmiheader;
// Draw
CDIBSectionLite dibsection;
dibsection.SetBitmap(&bmi, (void*)pBaseBits); // fail at here
hDC = GetDC(m_hwnd);
CDC dc;
dc.Attach(hDC);
dibsection.Draw(&dc, CPoint(0,0), FALSE);
dc.Detach();
ReleaseDC(m_hwnd, hDC);
But i found in SetBitmap function
m_hBitmap = CreateDIBSection(hDC, (const BITMAPINFO*) m_DIBinfo,
m_iColorDataType, &m_ppvBits, NULL, 0);
return NULL;
I have compare the same project in PC
seems there is no difference, could anyone help out?
thanks!!!!
|
|
|
|
|
try calling ::GetLastError after the CreateDIBSection that fails.
-c
As always, it's bread and circuses. And while bread is down right now, circuses are way up.
|
|
|
|
|
Got error number 87 : ERROR_INVALID_PARAMETER
seems there is a parameter incorrect, but same code in pc is ok!
I am puzzle, whether the interface:
BOOL CDIBSectionLite::SetBitmap(LPBITMAPINFO lpBitmapInfo, LPVOID lpBits)
can be use in PPC2002?
I have check the parameter of
m_hBitmap = CreateDIBSection(hDC, (const BITMAPINFO*) m_DIBinfo,
m_iColorDataType, &m_ppvBits, NULL, 0);
the only different is in pc iColorDataType is 0
but in ce it return 3
becuase in NumColorEntries function it has current
code for 32 bit color
#ifdef _WIN32_WCE
nColors = 3; // I've found that PocketPCs need this regardless of BI_RGB or BI_BITFIELDS
How could i do ???
#else
|
|
|
|
|
See my reply below titled:
Re: Need Help 16/32 Bpp on PocketPc
(or use this link)
http://www.codeproject.com/bitmap/dibsection.asp?forumid=56&select=187087&df=100#xx187087xx
I think it may solve your problem.
-jim
|
|
|
|
|
hello
how is the BMP files, structure ?and how can we read these kinds of files in a different environment like DELPHI or vISUAL C++ without disturbing the source file?
|
|
|
|
|
What do you mean by disturbing ? Reading a file will not write to it, but it does have the read it. GDI+ provides the easiest way to read/write different type of image files in VC.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
how do I display a symbol on a displayed bitmap?
please help.
suguna
|
|
|
|
|
You need to draw it onto the bitmap, or the DC which is displaying the bitmap.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hi
My name i s omer, and im tryin to develope a network desktop monitoring utility,and thanx 2 u i was able to be where i am now in my project, but im stuckat one problem.
Following is the code at server side, when server recieves a command for sendits of desktop !
void CServerDlg::SendDesktop()
{
CBitmap bitmap;
CWindowDC dc(GetDlgItem(IDD_SERVER_DIALOG));
CDC memDC;
memDC.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc, 400,300);
for(int i=0;i<20;i++)
{
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.StretchBlt(0, 0, 400,300, &dc, 0, 0,800,600,SRCCOPY);
memDC.SelectObject(pOldBitmap);
myBitmap.SetBitmap(bitmap);
// GENERATE DATA TO BE SENT
BITMAPINFO bmi=(*myBitmap.GetBitmapInfo());
void *ptr;
ptr=malloc(myBitmap.GetImageSize()+sizeof(BITMAPINFO));
// copy info
memcpy(ptr,&bmi,sizeof(BITMAPINFO));
// copy bits
memcpy((LPBYTE)ptr+sizeof(BITMAPINFO),myBitmap.GetDIBits(),myBitmap.GetImageSize());
m_ServerSocket.Send(ptr,myBitmap.GetImageSize()+sizeof(BITMAPINFO));
free(ptr);
/*for(int j=0; j<2000;j++)
for(int k=0; k<2000;k++);*/
}
}
Now command comes from the client which inturn recieves the command as folllows
void CClientDlg::OnRecieve()
{
int len=0;
len=m_ClientSocket.Receive(ptr,37000);
memcpy((LPBYTE)dataptr+datalen,ptr,len);
datalen+=len;
if(datalen>=360044)
{
m_dib.SetBitmap((BITMAPINFO*)dataptr,(LPBYTE)dataptr+sizeof(BITMAPINFO));
m_dib.Draw(this->GetDC(),CPoint(0,0));
datalen=0;
}
}
The problem is when the client dialog looses focus then client application shuts down. sometimes even when its workin alright, this error generates.
i know im askin for a lot , but please im approachin my deadline in coming month.
u can contact me at omee4u@yahoo.com any time
lookin forward to ur reply!
|
|
|
|
|
we have to use 240 instead of 248 in CDIBSectionLite::CreateHalftonePalette()...
BOOL CDIBSectionLite::CreateHalftonePalette(CPalette& palette, int nNumColors)
{
...
for (i = 8; i < 16; i++)
{
pi.palPalEntry[i].peRed = ms_StdColors[240+i].rgbRed;
pi.palPalEntry[i].peGreen = ms_StdColors[240+i].rgbGreen;
pi.palPalEntry[i].peBlue = ms_StdColors[240+i].rgbBlue;
pi.palPalEntry[i].peFlags = 0;
}
...
}
|
|
|
|
|
Dear Chris,
thanks very much for the CDIBSectionLite Wrapper class. It proved to be
very helpfull in my last project.
I needed CObject-Style serialization support ( see below ), maybe you like to add it to the class.
Best regards
Gernot
Serialization support a la CObject:
Add to Class Definition:
/////////////////////////////////////////
public:
DECLARE_SERIAL( CDIBSectionLite );
protected:
void Serialize( CArchive& ar );
//////////////////////////////////////////
Add to implementation:
//////////////////////////////////////////
IMPLEMENT_SERIAL( CDIBSectionLite, CObject, VERSIONABLE_SCHEMA | 0 )
void CDIBSectionLite::Serialize( CArchive& ar )
{
if( ar.IsStoring() )
{
// first write BITMAPINFO
LPBITMAPINFO lpbi = GetBitmapInfo();
if( lpbi == NULL )
ar << 0L; // if no BITMAPINFO available, just write 0
else
{
// else write size of strukture and the strukture
ar << sizeof(BITMAPINFO);
ar.Write( lpbi, sizeof(BITMAPINFO) );
// now write BITS
LPVOID pBits = GetDIBits();
if( pBits == NULL )
ar << 0L;
else
{
// write size of bits and the bits
long bitSize = lpbi->bmiHeader.biSizeImage;
ar << bitSize;
ar.Write( pBits, bitSize );
}; // if pBits == NULL
}; // if lpbi == NULL
}
else
{
// Get the version number for further changes; not used yet
UINT nVersion = ar.GetObjectSchema();
LPBITMAPINFO lpbi = NULL;
LPVOID lpBits = NULL;
// First load BITMAPINFO
long infoSize;
ar >> infoSize; // size of BITMAPINFO
if( infoSize > 0 )
{
ASSERT( infoSize == sizeof(BITMAPINFO) ); // better error handling needed??
lpbi = new BITMAPINFO;
ar.Read( lpbi, infoSize );
// now read Bits
long bitSize;
ar >> bitSize;
if( bitSize > 0 )
{
lpBits = new BYTE[bitSize];
ar.Read( lpBits, bitSize );
}; // if bitSize > 0
}; // if infoSize > 0
// now aply new data
SetBitmap( lpbi, lpBits );
// delete the sturktures
delete lpbi;
delete lpBits;
}; // if ar.IsStoring
}; // Serialize
//////////////////////////////////////////
|
|
|
|
|
How to load bitmap ftom the clipboard to CDIBSectionLite?
|
|
|
|
|
I am looking for some information on how write an application and driver to capture AVI clips and preview/playback of AVI clips on WinCE platform. Can anybody help?
Thank you.
|
|
|
|
|
Hi Chris,
I want to thank you for your article and the coding first. It's very easy to use and it's very powerful.
When I am using it, I have a question:
At first, I opened a 256-grey-scale bitmap file, using
m_pdib->Load("mybitmap.bmp");
Then in OnDraw(CDC *pDC)
{
m_pdib->Draw(pDC, pt, TRUE);
CPen redPen;
VERIFY(redPen.CreatePen(PS_SOLID, 1, RGB(255,0,0)));
CPen *pOldPen = pDC->SelectObject(&redPen);
pDC->Ellipse(pt.x, pt.y, pt.x+10, pt.y+10);
pDC->SelectObject(pOldPen);
}
The problem is: the bitmap file will be displayed correctly, but the red circle will not be displayed. I tried to use a white pen, but the circle couldn't be drawn either.
What did I do wrong?
Thank you very much for your help!
|
|
|
|
|
execuseme, I'm not good speak english.
I have one problem in WinCE..
I don't send document or text to printer in Embedded MFC .
I want send japan's and arabic character to IrDA printer..
please help me..
my mail adress: mgencer99@hotmail.com
MFC
|
|
|
|
|
I have compiled the source for Ipaq pocketpc but i am unable to display the 16 bpp and the 32 bpp images.
However all the other formats works including the 24 Bpp.
Are the 16/32 bpp formats not supported or am i missing something
Maklouf
|
|
|
|
|
I had the same problem, here's how I solved it (in my case)
in:
BOOL CDIBSectionLite::SetBitmap(HBITMAP hBitmap
{
:
:
#ifdef _WIN32_WCE
//DCR 4/02/01 I've found PocketPCs need BI_BITFIELDS for 16 bit dibs.
if (bm.bmBitsPixel == 16 || bm.bmBitsPixel == 32)
bih.biCompression = BI_BITFIELDS;
else
bih.biCompression = BI_RGB;
#else
bih.biCompression = BI_RGB;
#endif
:
:
}
Then in:
BOOL CDIBSectionLite::Load(CFile &file)
{
:
:
int nColors = NumColorEntries(BmpInfo.bmiHeader.biBitCount, BmpInfo.bmiHeader.biCompression, BmpInfo.bmiHeader.biClrUsed);
if (nColors == 3) {
//DCR 4/02/01 If you are dealing with a 16bpp bitmap in PocketPC, you must
// set the 3 DWORD color mask. This mask will be applied to a 16bit value to find the
// RGB components. Blue is lowest 5 bits, then Green, then Red.
if (BmpInfo.bmiHeader.biBitCount == 16)
{
DWORD dw[3];
dw[0] = 31744; //RED bitmask Bits: 0 11111 00000 00000
dw[1] = 992; //GREEN bitmask Bits: 0 00000 11111 00000
dw[2] = 31; //BLUE bitmask Bits: 0 00000 00000 11111
memcpy(BmpInfo.ColorTable(), dw, 3 * sizeof(RGBQUAD));
BmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
}
} else
if (nColors > 0)
{
// Read the color table from the file.
int nColorTableSize = nColors * sizeof(RGBQUAD);
nBytes = file.Read(BmpInfo.ColorTable(), nColorTableSize);
if (nBytes != nColorTableSize)
{
TRACE0("Failed to read color table\n");
return FALSE;
}
}
:
:
}
Basically, you need to tell the PPC that the 3 colour entries are bit masks for the RGB.
|
|
|
|
|
HOW TO SEND FILE BY THE NETWORK,USING MFC?
PLEASE REPLY;)
|
|
|
|
|
what I do is (client send a 1024 bytes long file to server)
on client:
1. create a TCP/IP socket
2. connect
3. buffer[0] = 4,
sprintf(&buffer[1], "%d", 1024);
send(sd, buffer, strlen(buffer), 0);
4. int nBytesSent = 0; int nRet;
while(nBytesSent<1024)
{
nRet = send(sd, file+nBytesSent, (1024-nBytesSent), 0);
nBytesSent += nRet;
if ( nRet == SOCKET_ERROR )
break;
}
5. closesocket
on server
1. create a TCP/IP socket
2. accept
3. recv(sd, buffer, sizeof(buffer));
char temp[10]; memcpy(temp, &buffer[1], buffer[0]);
int nTotalBytes = atoi(temp);
4. int nBytesRcvd = 0; int nRet;
while(nBytesSent<nTotalBytes)
{
nRet = recv(sd, file+nBytesRcvd , (nTotalBytes-nBytesRcvd ), 0);
nBytesRcvd += nRet;
if ( nRet == SOCKET_ERROR )
break;
}
5. closesocket
that's it.
|
|
|
|
|
I'll like to compress the BMP files resulting from a screen capture (106 ko -24 bpp). Does DIBSection accept a compression like RLE ?
Christian.
Christian ARVOR, developping on Nec MobilePro VC++ 3.0
|
|
|
|
|
I am writing a program that captures (24-bit) single frames from a live video feed, and I've been trying for over 3 weeks to get the bitmap stored on the clipboard. I added these functions to the CDIBSectionLite class:
HANDLE CDIBSectionLite::PutOnClipboard()
{
HANDLE hResult = NULL;
if (::OpenClipboard(NULL))
{
::EmptyClipboard();
::GdiFlush();
hResult = ::SetClipboardData(CF_DIB, CopyHandle((HANDLE)m_hBitmap));
if (hResult == NULL)
{
_ShowLastError();
}
::CloseClipboard();
}
return hResult;
}
HANDLE CDIBSectionLite::CopyHandle()
{
if (!m_hBitmap)
{
ASSERT(FALSE);
return NULL;
}
DWORD dwLen = ::GlobalSize(m_hBitmap);
if (dwLen == 0)
{
dwLen = sizeof(m_DIBinfo) + GetImageSize();
}
HANDLE hCopy = ::GlobalAlloc(GHND, dwLen);
if (hCopy != NULL)
{
BYTE* lpCopy = (BYTE*)::GlobalLock(hCopy);
BYTE* lp = (BYTE*)::GlobalLock(m_hBitmap);
::CopyMemory(lpCopy, lp, dwLen);
::GlobalUnlock(hCopy);
::GlobalUnlock(m_hBitmap);
}
else
{
_ShowLastError();
return NULL;
}
return hCopy;
}
HANDLE CDIBSectionLite::CopyHandle(HANDLE h)
{
if (!h)
{
ASSERT(FALSE);
return NULL;
}
DWORD dwLen = ::GlobalSize(h);
if (dwLen == 0)
{
dwLen = sizeof(m_DIBinfo) + GetImageSize();
}
HANDLE hCopy = ::GlobalAlloc(GHND, dwLen);
if (hCopy != NULL)
{
BYTE* lpCopy = (BYTE*)::GlobalLock(hCopy);
BYTE* lp = (BYTE*)::GlobalLock(h);
::CopyMemory(lpCopy, lp, dwLen);
::GlobalUnlock(hCopy);
::GlobalUnlock(h);
}
else
{
_ShowLastError();
return NULL;
}
return hCopy;
}
If I call CopyHandle(), the program crashes at the line that calls the CopyMemory() function because lp is NULL. It doesn't matter which version of the CopyHandle() function I use.
I know that the bitmap is a good one because if I save the bitmap to a file, it saves a valid BMP file.
Here's the code I'm using to do this:
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader = cb.bih;
CDIBSectionLite dib;
dib.SetBitmap(&bmi, cb.pBuffer);
dib.Save("e:\\blah.bmp");
dib.PutOnClipboard();
To hell with those thin-skinned pillow-biters. - Me, 10/03/2001
|
|
|
|
|
My paint program copied a DIBSection to the clipboard like this:
::EmptyClipboard();
::SetClipboardData(CF_BITMAP,(HBITMAP)pDIB->GetHandle());
::CloseClipboard();
pDIB is an instance of a DIBSection wrapper from Paintlib, if I recall. GetHAndle returns the DIBSection handle, it is almost certainly equivelant to m_hBitmap. However, you're putting a member variable onto the clipboard, you should create a local copy ( I deleted that portion of my code for clarity, it was Paintlib specific ) and then regard it as no longer your property once it's been passed to the clipboard.
A DIB is different to a DIBSection, which is both device independant but also has a HBITMAP so you can use it in GDI drawing. I suspect maybe using CF_BITMAP instead of CF_DIB might help you also.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I was trying to copy the handle, so it should have been fine. Oh well - I'll give your way a shot and see if it works for me.
Many thanks, lord of the GDI.
To hell with those thin-skinned pillow-biters. - Me, 10/03/2001
|
|
|
|
|
It put something on the clipboard when I did this:
::EmptyClipboard();
::SetClipboardData(CF_BITMAP,(HBITMAP)GetSafeHandle());
::CloseClipboard();
But when I try to paste from the clipboard (into Paint for instance), I get an error that says the clipboard format is invalid.
To hell with those thin-skinned pillow-biters. - Me, 10/03/2001
|
|
|
|
|
The thing is, GetSafeHandle returns m_hBitmap, BUT the destructor deletes this handle, so if you've created a copy using this class, it's surely bound to fail unless the instance of the class has not been destroyed when you go to paste ?
I think you need to add a CopyToClipboard function that makes a new DIBSection, copies m_hBitmap to it, paasses it to the clipboard and then does not DeleteObject on the copy. I suspect that this is the reason it's going in OK, but it's gone when you go to paste it.
The following function works, but creates a DDB compatible with the screen, and it uses MFC. The bits commented out where my attempts to make it work with a DIBSECTION, but it just didn't want to work. If this isn't what you want, hopefully it's a starting point. Just put this code into DIBSectionLite as a function called ToClipboard or whatever, and call it.
if (!m_hBitmap) return;
CDC myDC;
myDC.CreateCompatibleDC(NULL);
CBitmap * pBitmap = new CBitmap;
pBitmap->CreateBitmap(GetWidth(), GetHeight(), 1, GetDeviceCaps(myDC, BITSPIXEL), NULL);
myDC.SelectObject(pBitmap);
Draw(&myDC, CPoint(0,0));
myDC.DeleteDC();
BOOL bOpen = ::OpenClipboard(AfxGetMainWnd()->GetSafeHwnd());
if (bOpen)
{
::EmptyClipboard();
::SetClipboardData(CF_BITMAP,pBitmap->GetSafeHandle());
::CloseClipboard();
pBitmap = NULL;
}
else
AfxMessageBox("Unable to open clipboard");
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|