Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Serializing Bitmaps/Icons

Posted on 1998-03-15
4
Medium Priority
?
343 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 300 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

610 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