本文整理汇总了C#中System.IO.StreamReader.ReadNextChunkDiscardComments方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.ReadNextChunkDiscardComments方法的具体用法?C# StreamReader.ReadNextChunkDiscardComments怎么用?C# StreamReader.ReadNextChunkDiscardComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了StreamReader.ReadNextChunkDiscardComments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPNM
public static int[,] LoadPNM(string imgf)
{
var textr = new StreamReader(imgf);
string pnmformat = textr.ReadNextChunkDiscardComments();
if (pnmformat != "P1" && pnmformat != "P2")
throw new Exception("PNM format "+pnmformat+" not supported");
int width = textr.ReadNextChunkDiscardComments().ToInt();
int height = textr.ReadNextChunkDiscardComments().ToInt();
int maxval = 0;
if (pnmformat != "P1")
maxval = textr.ReadNextChunkDiscardComments().ToInt();
//maxval = 255; // ignoring value written in file
if (pnmformat == "P1")
return LoadPBMData(textr, width, height);
else if (pnmformat == "P2")
return LoadPGMData(textr, width, height, maxval);
throw new Exception("PNM format "+pnmformat+" didn't match supported");
}
示例2: LoadPGMData
public static int[,] LoadPGMData(StreamReader textr, int width, int height, int maxval)
{
int[,] data = new int[width, height];
int y = 0;
int x = 0;
while (true) {
string nexts = textr.ReadNextChunkDiscardComments();
if (nexts == null) break;
data[x,y] = nexts.ToInt();
++x;
if (x >= width) {
++y;
x = 0;
}
}
if (y != height || x != 0) {
throw new Exception("specified dimensions not correct, have ("+x.ToString()+","+y.ToString()+") instead of ("+width.ToString()+","+height.ToString()+")");
}
textr.Close();
return data;
}