Solved

Serializing Bitmaps/Icons

Posted on 1998-03-15
4
296 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now