Archived

This topic is now archived and is closed to further replies.

rossco

Store a bitmap file as a field in a text file using C/C++

Recommended Posts

rossco    103
I am writing an electronic voting system and I want to store the candidate''s photograph as a field in the candidate file along with the candidate''s firstname surname and gender. How do I store this picture/image as a field in text file using C/C++?

Share this post


Link to post
Share on other sites
BriTeg    168
If you want to store the bitmap in the same file as the name, you need to use a binary file, not a text file. And you need to come up with your own format/layout. Here''s an example:

- int: firstname length, including terminating nul
- bytes: firstname, null-terminated string
- int: surname length, including terminating nul
- bytes: surname, null-terminated string
- int: gender (0=male, 1=female)
- int: number of bytes in bitmap data
- bytes: bitmap data

Then you:
- open the file
- read an int - this tells you how many bytes to read for the first name
- read that many more bytes, store the data in the firstname
- read an int - this tells you how many bytes to read for the surname
- read that many more bytes, store the data in the surname
- read an int - this tells you the gender
- read an int - this tells you how many bytes to read for your bitmap info
- read that many more bytes, pass that data to your bitmap handling code.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You could encode the binary file as text.

You could simply use something like uuencode/uudecode to convert the binary bitmap file to ASCII and back.

I haven''t explicitly dealt with the programs in years though, but this is similar to how many email systems and usenet groups transfer(ed) binary files.

Share this post


Link to post
Share on other sites