Click to See Complete Forum and Search --> : About monochrome format


jbuitrago
June 24th, 2002, 06:53 AM
I need to read a monochrome image in C++ but there is no a function or something like that. The problem is to read it, available definitions in C++ donīt permit to work in binary format and I need the code source that permits it. Thanks a lot.

cup
June 24th, 2002, 01:25 PM
Are you trying to read a .bmp file? If all else fails in C++, you could fall back into C and use FILE*. eg

#include <stdio.h>
FILE* image = fopen ("filename", "r+b"); // b means binary
fread (
buffer, // The input buffer - you have to new this
1, // size of each item
size, // total size
image);

I haven't done binary I/O in C++. I'll dig through my books and see what there is.

cup
June 24th, 2002, 02:21 PM
I don't know if this is VC++ specific. To open a binary file using streams, use

ifstream bmp(bmpfilename);
bmp.setmode(filebuf::binary);

The default is filebuf::text.