 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
poojo hackma Guest
|
Posted: Wed Apr 04, 2007 11:55 pm Post subject: Bitmap GetObject |
|
|
First, I must say that this is being done in eMbedded VC 4.0 for a Pocket
PC, not in Borland; however, the techniques should be the same for native
API usage, so I wanted to post the question here.
It has taken me a little time, but I have narrowed my problem down to
CBitmap::GetObject.
My application loads many images. The frequently used ones have been
converted to bitmaps and are loaded as resources, but the rest are still in
JPEG format on the device's Compact Flash storage card.
To load a JPEG, I use SHLoadImageFile from the Pocket PC SDK. To load a
resource bitmap, I use the LoadBitmap API (see code below).
The problem comes when I attempt to call GetObject on a jpeg file. The image
displays correctly, but parts of my program get overwritten whenever it
happens. (Currently, CStringList files is being overwritten, but if the
declaration order gets changed around somewhat, it will go to something
else.)
Could someone look at my use of GetObject and tell me what I am doing wrong?
Could you suggest a way to fix it?
void CForm1Dlg::OnPaint()
{
CBitmap bitmap, *pOldbmp;
CPaintDC dc(this);
BITMAP BMP;
CDC mDC;
DWORD ok;
HBITMAP hBMP;
if (bImageIsJpegFile)
hBMP = SHLoadImageFile(szImageFile);
else
hBMP = LoadBitmap(AfxGetApp()->m_hInstance,
MAKEINTRESOURCE(IDB_IMAGE2));
if (hBMP == NULL)
return;
ok = bitmap.Attach(hBMP);
if (!ok)
return;
// Help says if I pass NULL as param2, GetObject returns the
// size needed to allocate for the bitmap object:
ok = bitmap.GetObject(sizeof(BITMAP), NULL);
// problem is, GetObject above always returns ok=84.
// Any idea what that would mean?
if (!ok)
return;
// In the GetObject below, if hBMP is to a JPEG file,
// other areas of my application get overwritten.
// Does anyone know why?
ok = bitmap.GetObject(ok, &BMP);
// CStringList files was 56, now it is 0.
if (!ok)
return;
mDC.CreateCompatibleDC(&dc);
pOldbmp = mDC.SelectObject(&bitmap);
if (pOldbmp != NULL)
{
dc.StretchBlt(r.left, r.top, r.Width(), r.Height(), &mDC,
0, 0, BMP.bmWidth, BMP.bmHeight, SRCCOPY);
mDC.SelectObject(pOldbmp);
mDC.DeleteDC();
}
mDC.ReleaseAttribDC();
}
Thanks in advance!
~Joe |
|
| Back to top |
|
 |
Thomas Maeder [TeamB] Guest
|
Posted: Thu Apr 05, 2007 12:40 am Post subject: Re: Bitmap GetObject |
|
|
"poojo hackma" <poojo.com/mail> writes:
| Quote: | CBitmap bitmap, *pOldbmp;
|
What's CBitmap? |
|
| Back to top |
|
 |
poojo hackma Guest
|
Posted: Thu Apr 05, 2007 12:59 am Post subject: Re: Bitmap GetObject |
|
|
CBitmap is an MFC bitmap class that "encapsulates the functionality of a
Windows CE graphics device interface (GDI) bitmap."
I suppose if no one here knows what a CBitmap is, I'm not going to be able
to get much help.
Thanks anyway.
"Thomas Maeder [TeamB]" wrote:
|
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Thu Apr 05, 2007 7:05 pm Post subject: Re: Bitmap GetObject |
|
|
poojo hackma wrote:
| Quote: | void CForm1Dlg::OnPaint()
{
BITMAP BMP;
24 bytes of data |
| Quote: | // Help says if I pass NULL as param2, GetObject returns the
// size needed to allocate for the bitmap object:
ok = bitmap.GetObject(sizeof(BITMAP), NULL);
// problem is, GetObject above always returns ok=84.
// Any idea what that would mean?
|
It means you nead an 84 byte data area for the object.
| Quote: | // In the GetObject below, if hBMP is to a JPEG file,
// other areas of my application get overwritten.
// Does anyone know why?
ok = bitmap.GetObject(ok, &BMP);
|
You just wrote 84 bytes of data to an area that is 24 bytes in size.
The reason you call it with NULL in the first place, is to allocate
enough space for the real call, but you never do that. |
|
| Back to top |
|
 |
Thomas Maeder [TeamB] Guest
|
Posted: Thu Apr 05, 2007 8:56 pm Post subject: Re: Bitmap GetObject |
|
|
"poojo hackma" <poojo.com/mail> writes:
| Quote: | CBitmap is an MFC bitmap class that "encapsulates the functionality
of a Windows CE graphics device interface (GDI) bitmap."
I suppose if no one here knows what a CBitmap is, I'm not going to
be able to get much help.
|
Well, I reall know very little about the MFC, but I know that its
classes are named with prefix 'C', so I guessed that CBitmap might in
fact be the/a MFC bitmap class. Then again, I thought that you would
have told us in your original post.
Now that I know, I am surprised that you didn't post your question to
a MFC related newsgroup. |
|
| Back to top |
|
 |
poojo hackma Guest
|
Posted: Thu Apr 05, 2007 9:02 pm Post subject: Re: Bitmap GetObject |
|
|
Hi Mr. Gonder.
Thanks for the info!
What should be allocated 84 bytes? My CBitmap object "bitmap" and my BITMAP
structure "BMP" are both heap allocated.
There is an "LPVOID bmBits" in the BITMAP structure. Should I allocate 84
bytes of data, then point the bmBits to it?
typedef struct tagBITMAP {
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
} BITMAP;
"Bob Gonder" wrote:
| Quote: | You just wrote 84 bytes of data to an area that is 24 bytes in size.
The reason you call it with NULL in the first place, is to allocate
enough space for the real call, but you never do that.
|
|
|
| Back to top |
|
 |
poojo hackma Guest
|
Posted: Thu Apr 05, 2007 11:36 pm Post subject: Re: Bitmap GetObject |
|
|
Oh, I did! But they get flooded with so many messages that if no one can
answer it in a day, it gets stuffed so far back in the queue that no one
will ever see it again.
And, they don't typically like to share their information or take the time
to show someone how to do it correctly, which is one of the things I've
always liked about this board.
Speaking of which, someone say hello to Gambit for me.
"Thomas Maeder [TeamB]" writes:
| Quote: | Now that I know, I am surprised that you didn't post your question to
a MFC related newsgroup. |
|
|
| Back to top |
|
 |
Bruce Salzman Guest
|
Posted: Fri Apr 06, 2007 12:39 am Post subject: Re: Bitmap GetObject |
|
|
"poojo hackma" <poojo.com/mail> wrote in message
news:4613f4bc (AT) newsgroups (DOT) borland.com...
| Quote: | Could someone look at my use of GetObject and tell me what I am
doing wrong? Could you suggest a way to fix it?
// In the GetObject below, if hBMP is to a JPEG file,
// other areas of my application get overwritten.
// Does anyone know why?
ok = bitmap.GetObject(ok, &BMP);
|
Why not use GetBitmap()?
--
Bruce |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Fri Apr 06, 2007 4:16 am Post subject: Re: Bitmap GetObject |
|
|
poojo hackma wrote:
| Quote: | What should be allocated 84 bytes? My CBitmap object "bitmap" and my BITMAP
structure "BMP" are both heap allocated.
There is an "LPVOID bmBits" in the BITMAP structure. Should I allocate 84
bytes of data, then point the bmBits to it?
|
No.
I really know nothing about using jpegs, but I'd bet from what you
have said, that GetObject on a jpeg isn't going to return (just) a
BITMAP.
Something along the lines of
ok = bitmap.GetObject( 0, NULL );
if( ok )
{
char*buffer = new char[ok];
bitmap.GetObject( ok, buffer );
}
OTOH, reading up on CBitmap, I see that what you probably wanted to do
was
ok = bitmap.GetObject( sizeof(BMP), &BMP );
and forget about using the NULL version.
Though it would be easier to use Bruce's suggestion, and do
ok = bitmap.GetBitmap( & BMP ); |
|
| Back to top |
|
 |
poojo hackma Guest
|
Posted: Mon Apr 09, 2007 6:21 pm Post subject: Re: Bitmap GetObject |
|
|
"Bob Gonder" wrote:
| Quote: | OTOH, reading up on CBitmap, I see that what you probably wanted to do
was
ok = bitmap.GetObject( sizeof(BMP), &BMP );
and forget about using the NULL version.
|
That was how I started. I had problems with it, so I started trying to get
the size before getting the object.
| Quote: | Though it would be easier to use Bruce's suggestion, and do
ok = bitmap.GetBitmap( & BMP );
|
Yes, I see that! Probably a much better method!
Thanks for your time, Mr. Gonder.
~Joe |
|
| Back to top |
|
 |
poojo hackma Guest
|
Posted: Mon Apr 09, 2007 6:23 pm Post subject: Re: Bitmap GetObject |
|
|
Thanks for the pointer, Bruce. I had originally passed over this method,
thinking I could not use it if I was opening a JPEG file. Later, I learned
that the SDK tool SHLoadImageFile actually returns a bitmap that I can use
with GetBitmap.
I think the problem is solved.
Thanks again!
~Joe
" Bruce Salzman" wrote:
| Quote: | Why not use GetBitmap()?
--
Bruce |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|