图片文件读取到内存,然后返回内存中图片,用于解除锁定

来源:互联网 发布:cocos2d-js webgl 编辑:程序博客网 时间:2024/06/05 23:45
    /// <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; }       }
0 0