/// <summary>
/// 图片文件读取到内存,然后返回内存中图片,用于解除锁定
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static Image ReadImageFromFile(string path)
{
try
{
System.IO.FileStream fs = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read);
int byteLength = (int)fs.Length;
byte[] fileBytes = new byte[byteLength];
fs.Read(fileBytes, 0, byteLength);
//文件流关閉,文件解除锁定
fs.Close();
Image imgNow = Image.FromStream(new MemoryStream(fileBytes));
return imgNow;
}
catch { return null; }
}
图片文件读取到内存,然后返回内存中图片,用于解除锁定
最新推荐文章于 2025-11-25 10:25:40 发布
本文介绍了一种从文件系统中读取图片并将其加载到内存的方法,该方法能够有效解除对原始文件的锁定,适用于需要频繁操作图片的应用场景。

1309

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



