How would you do this?
I thought something like this would work but it doesn due to operator<< not being defined or something.
Code:
class SerialBitmap : public CBitmap {
DECLARE_SERIAL(SerialBitmap)
public:
virtual void Serialize(CArchive& ar);
};
Code:
IMPLEMENT_SERIAL(SerialBitmap, CBitmap, 3);
void SerialBitmap::Serialize(CArchive& ar)
{
BITMAP bmp;
if (ar.IsStoring()) {
GetBitmap(&bmp);
ar << bmp.bmType;
ar << bmp.bmWidth;
ar << bmp.bmHeight;
ar << bmp.bmWidthBytes;
ar << bmp.bmPlanes;
ar << bmp.bmBitsPixel;
BYTE* bits = (BYTE*)bmp.bmBits;
for (int i = 0; i < bmp.bmHeight; ++i) {
for (int j = 0; j < bmp.bmWidthBytes; ++j) {
ar << *bits;
bits++;
}
}
} else {
ar >> bmp.bmType;
ar >> bmp.bmWidth;
ar >> bmp.bmHeight;
ar >> bmp.bmWidthBytes;
ar >> bmp.bmPlanes;
ar >> bmp.bmBitsPixel;
bmp.bmBits = malloc(bmp.bmHeight * bmp.bmWidthBytes);
BYTE* bits = (BYTE*)bmp.bmBits;
for (int i = 0; i < bmp.bmHeight; ++i) {
for (int j = 0; j < bmp.bmWidthBytes; ++j) {
ar >> *bits;
bits++;
}
}
SetBitmapBits(bmp.bmHeight * bmp.bmWidthBytes, (const void*)bits);
SetBitmapDimension(bmp.bmWidth, bmp.bmHeight);
}
}