Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » LoadBMP_Buffer Collapse All
Subject Author Date
Douglas Hoppes Mar 16, 2011 - 12:21 PM

Hi all,

I’m running into an issue that I hope someone can help with. I have a 24 bit image thumbnail that I need to display in a grid control. If I load the bitmap from a file, everything works fine. However, I’m trying to load the images from my image buffer.

In my image, I can get the image buffer that return an UCHAR*. How do I load this into a CExtBitmap?

I don’t see my image when I use:

// Load image into grid image buffer
        int totalsize = pThumbnail->width() * pThumbnail->height() * 3;
        pBmp->LoadBMP_Buffer(pThumbnail->buffer(), totalsize, false, true);

// Show the image
        CExtGridCellPicture * pCellPicture = STATIC_DOWNCAST(CExtGridCellPicture, GridCellGet(nColumn, nRow));
        ((CExtGridCellPictureRef*)pCellPicture)->BitmapSet(pBmp);

Like I said... if I’m loading the image from a file, the picture shows up. So, I’m pretty sure that the grid setup is correct. It’s just getting the information from my image buffer into CExtBitmap buffer.

Doug

Technical Support Mar 16, 2011 - 1:38 PM

The CExtBitmap::LoadBMP_Buffer() method loads a bitmap from a memory buffer containing binary bitmap data which has a BMP file format. This data can be preliminary loaded from a BMP file or a bitmap resource. It’s very important to specify correct bResourceFormat parameter flag because binary formats of BMP file and bitmap resource are not exactly the same. You specified true. If your bitmap buffer was loaded from BMP file, then you should specify false.

Douglas Hoppes Mar 17, 2011 - 11:20 AM

Thanks for the response. Still no go.

If I write my thumbnail to a bitmap file and then reloading the bitmap file using:
---------------------------------
CString sFilename;
sFilename.Format("c:\\internet\\download\\CBitmap%d.bmp", i);
CImage image;
image.Attach(pThumbnail->win_hbitmap());
image.Save(sFilename);
image.Detach();
pBmp->LoadBMP_File(sFilename);

CExtBitmap *pBitmap = reinterpret_cast<CExtBitmap *>(pValue);
((CExtGridCellPictureRef*)pCellPicture)->BitmapSet(pBitmap);
---------------------------------

Everything works fine. However, I need to go directly from the CBitmap (MFC) object to the CExtBitmap object. To do this, I use:
---------------------------------
pBmp->LoadBMP_Buffer(pThumbnail->win_bmh(), pThumbnail->bufferwidth());

CExtBitmap *pBitmap = reinterpret_cast<CExtBitmap *>(pValue);
((CExtGridCellPictureRef*)pCellPicture)->BitmapSet(pBitmap);
---------------------------------
and it doesn’t work. I just get white blanks in my table.

Doug

Technical Support Mar 18, 2011 - 6:03 AM

There is not enough information about what is pThumbnail? Prof-UIS widely uses bitmap serializations. We always load and save bitmaps using our own code written from scratch. Customized icons in toolbars and menus are 32-bit bitmaps with alpha channel and they are serialized. So, we cannot assume the CExtBitmap::LoadBMP_Buffer() method does not work.
You can use the CExtBitmap::FromBitmap() API to construct CExtBitmap object from CBitmap or HBITMAP if you need this.

Douglas Hoppes Mar 18, 2011 - 6:12 AM

THANKS!!!!! The FromBitmap() function works beautifully!

Douglas Hoppes Mar 18, 2011 - 6:07 AM

Thanks... I’ll try that (CExtBitmap::FromBitmap()). That may work

Sorry, I wasn’t implying that the function didn’t work. I meant that I couldn’t get the function to work.

In this case, pThumbnail is a CBitmap (MFC).