Yin Zhu
Yin Zhu

Reputation: 17119

read a file with both text and binary information in .Net

I need to read binary PGM image files. Its format:

P5
# comments
nrows ncolumns
max-value
binary values start at this line. (totally nrows*ncolumns bytes/unsigned char)

I know how to do it in C or C++ using FILE handler by reading several lines first and read the binary block. But don't know how to do it in .Net.

Upvotes: 3

Views: 1227

Answers (2)

Kamran Khan
Kamran Khan

Reputation: 9986

Try looking into Stream.Read() method. Here is how you'd read a binary file in C#. This article discusses upon reading a PGM file.

Upvotes: 1

Zach Johnson
Zach Johnson

Reputation: 24212

You should look into System.IO.Stream (and its inheriting classes, such as FileStream) and the various reader classes.

Depending on the type of stream, you can set the position.

stream.Position = {index of byte};

You could read the first section, determine at which byte the binary part starts, and read the stream from there.

Upvotes: 0

Related Questions