public object GetImage(string path)
{
FileStream fs=new FileStream(path,FileMode.Open);
try
{
Image img =Image.FromStream(fs);
return img;
}
catch(Exception ex)
{
throw ex;
}
finally
{
fs.Close();
}
}
这种方法读取图片之后就释放掉资源。比较安全,不会报错。
本文介绍了一种使用FileStream和Image.FromStream安全地读取图片文件的方法,并确保了资源的正确释放,防止内存泄漏等问题。

被折叠的 条评论
为什么被折叠?



