Solved

Serializing Bitmaps/Icons

Posted on 1998-03-15
4
330 Views
Last Modified: 2013-11-19
I need to save bitmaps and icons while I'm serializing othe r data.  The CBitmap class doesn't seem to have a serialize method.  How can I serialize a bitmap?

I also need to serialize Icons.  Any tips?
0
Comment
Question by:mark2552
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316999
  I believe there is a "GetFile()" function that you can use off of a CArchive object (I am not at my computer right now).  You could get the CFile pointer, and then write the bitmap/icon data in any format that you wish.

-=- James.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1317000
There is code in the MS KB on how to write a bitmap to a file in BMP format.  This is probably a convenient way to write it - but you can use whetever format is most convenient.

Check out the DIBLOOK sample code for code to write bitmaps to a file.  This should be easily adapted to write to the CArchive instead.

I would be VERY wary of using GetFile() and then writeing directly to the file as this can get out of sync with the caching and buffering that CArchive does.

0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1317001
  No joke?!?

   I have used it before!  Is this considered dangerous?  The help system says that I just need to Flush() the archive object before using GetFile().  What other things do I need to be careful of?

-=- James.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1317002
Doing the CArchive::Flush() before the CArchive::GetFile() is necessary - I'd also call CFile::Flush() after, just to be sure.

I still feel a little uneasy when doing this sort of thing because it means there are two objects writing to the same file (the archive and your function) and in the weird and wonderful world of multitasking and messaging strange things _might_ happen.

If you already have a function for writing the bitmap to a standard BMP file, then using CArchie::Flush(), CArchive::GetFile(), CFile::Flush() should do the trick.

However, ensure that function for actually writing the bitmap to a file does NOT open the file nor close it. It should be passed a CFile and simply write to it.  If the bitmap writing routine closes the file, then that will stuff up your archiving.

However, if you don't already have such a routine, then you can avoid the possible risks and stuffing about by writing a BMP file writing routine but use CArchive::Write() to write directly to the CArchive - no need to do all this flushing etc.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
sumNumber challenge 16 140
changeXy challenge 13 93
wordcount challenge 11 145
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question