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
Solved

Serializing Bitmaps/Icons

Posted on 1998-03-15
4
325 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 80
Is there a simple front-end menu system. 9 103
x-bar in Google Sheets 2 70
Work with App store 7 68
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 …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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