?
Solved

Serializing Bitmaps/Icons

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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