tags:

views:

71

answers:

2

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.

A: 

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.

Zach Johnson
@downvoter: Why the downvote?
Zach Johnson
+1  A: 

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.

KMan