Encapsulated Dib API
Posted
by Jorge Lodos
on August 5th, 1998
The use of a class instead of global functions allowed for some extra features:
- The Dib maintains a CPalette member that updates automatically
- The BITMAPINFOHEADER structure and the image bits are kept in diferent data members (which allows for an easier access if image proccesing capabilities are added)
- Improved clipboard support implementation
- The Paint function (former PaintDIB) now includes palette support
- Serialization support (Serialize function implemented)
This class could be a starting point to a more complex image class. It has been used (among other things) to implement a static control to display images and a completely object oriented DIBLOOK. These articles can be found on the static control section and the samples section respectively.
Last updated: 24 June 1998

Comments
Bug in clipboard support
Posted by Legacy on 11/21/2000 12:00amOriginally posted by: Thomas Fritsch
ReplyBug in saving compressed bmps
Posted by Legacy on 11/07/2000 12:00amOriginally posted by: Arnt Witteveen
ReplyHow can I extend it to read the RGB value for each pixel ?
Posted by Legacy on 04/26/2000 12:00amOriginally posted by: Shahzad Alam
ReplyCDib cannot read certain files (RLE8 encoded) + fix
Posted by Legacy on 10/12/1999 12:00amOriginally posted by: Arnt Witteveen
ReplyBug fix
Posted by Legacy on 07/08/1999 12:00amOriginally posted by: Arnt & Kurt
Hi,
Thx for the code. Finally a readable CDib class :))
We found two bugs in your code though.
One is already mentioned : the fact that "Save(CFile& file)" uses the length of the file is wrong.
Here's the other one :
You gotta flush the archive before using ar.GetFile().
(press F1 while standing on GetFile, and look at the remark)
Otherwise you bmp will be saved in the beginning of the file that you are archiving.
void CDib::Serialize(CArchive& ar)
{
ar.Flush();
CFile* pFile = ar.GetFile();
ASSERT(pFile != NULL);
if (ar.IsStoring())
{ // storing code
Save(*pFile);
}
else
{ // loading code
Read(*pFile);
}
}
Greetings
ReplyArnt & Kurt
Minor Bug CDibStatic::PaintDIB
Posted by Legacy on 03/08/1999 12:00amOriginally posted by: Reinhard Bosch
I found a minor Bug in PaintDIB. If the image fits into the destination window,
the nDestWidth is set to m_DIB.Height() and nDestHeight to m_DIB.Width().
Recently I had tried to encapsulate the same DIBLOOK-Sample, but your
version is much more better.
Reinhard
ReplyEncountered an issue with Serialization
Posted by Legacy on 01/03/1999 12:00amOriginally posted by: Will Baldwin
Reply