Image.FromFile 锁文件的解决办法
用Image.FromFile加载图片会锁文件: Image image = Image.FromFile(fileName);
解决办法:
private Image GetImage(string fileName)
{
byte[] bytes = File.ReadAllBytes(fileName);
using (MemoryStream ms = new MemoryStream(bytes))
{
return Image.FromStream(ms);
}
}
{
byte[] bytes = File.ReadAllBytes(fileName);
using (MemoryStream ms = new MemoryStream(bytes))
{
return Image.FromStream(ms);
}
}
用这个方法来加载图片就可以了。