c#Image.FromFile图形加载异常处理

public void UpdateImg(string picpath)
{

//更新至控件中
PnlImageShow.BackgroundImage = LoadImgPath(picpath);
}

//读取PNG文件,生成Image对象

Image LoadImgPath(string picpath)
{

//默认资源文件
System.Drawing.Image bmp = Resources.defaultpic;

//判断文件是否存在
if (File.Exists(picpath))
{
FileStream image = new FileStream(
picpath,
FileMode.Open,
System.IO.FileAccess.Read,
FileShare.ReadWrite
);
bmp = Image.FromStream(image);
image.Close();
}


return bmp;

}

猜你喜欢

转载自www.cnblogs.com/xiaohua19920/p/9847965.html
今日推荐