Thread: Serial CBitmap

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    470

    Serial CBitmap

    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);
        }
    }
    Last edited by okinrus; 04-22-2004 at 10:43 PM.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Never mind. Found out that CBitmap does serialize.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Music Programming - Serial Matrix Display
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 04:16 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM