Saturday, November 29, 2014

Bitmap (Stream stream)

Your stream is already in use.


If you put a variable like a stream inside a foreach loop then that is a new variable each time it iterates.


I would consider something more like:



private List<string> FileList = new List<string>();
private void LoopFiles()
{
foreach(string path in FileList)
{
Image img = LoadImage(path);
System.Console.WriteLine(img.Width + " " + img.Height);
}
}

private Image LoadImage(string path)
{
var ms = new MemoryStream(File.ReadAllBytes(path));
return Image.FromStream(ms);
}

Obviously, you need to fill FileList with a list of file paths.





Hope that helps

Please don't forget to upvote posts which you like and mark those which answer your question.


No comments:

Post a Comment