开发者

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜