只读方式读取文件,防止被占用
//显示图片
pbCapture.Image = ExtendHelper.FileToImg(fileName); //pbCapture是System.Windows.Forms.PictureBox
public static Image FileToImg(string imageName)
{
try
{
using (FileStream s = new FileStream(imageName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var img = new Bitmap(s);
return img;
}
}
catch (Exception ex)
{
LogHelper.logger.Error($"FileToImg({imageName})", ex);
return null;
}
}