读取图片文件(C#实现)

 1  /// <summary>
 2         /// 读取图片文件
 3         /// </summary>
 4         /// <param name="path">图片文件路径</param>
 5         /// <returns>图片文件</returns>
 6         private Bitmap ReadImageFile(String path)
 7         {
 8             Bitmap bitmap=null;
 9             try
10             {
11                 FileStream fileStream = File.OpenRead(path);
12                 Int32 filelength = 0;
13                 filelength = (int)fileStream.Length;
14                 Byte[] image = new Byte[filelength];
15                 fileStream.Read(image, 0, filelength);
16                 System.Drawing.Image result = System.Drawing.Image.FromStream(fileStream);
17                 fileStream.Close();
18                 bitmap = new Bitmap(result);
19             }
20             catch (Exception ex)
21             { 
22                 //  异常输出
23             }
24             return bitmap;
25         }

 

posted @ 2017-06-27 20:06  王小豆又叫小王子  阅读(10082)  评论(0编辑  收藏  举报