收录日期:2021/01/26 17:21:17 时间:2010-03-31 04:06:32 标签:c#,.net,io

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.

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.

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.