using System.IO;
using System.Drawing;
/// <summary>
/// 將 Image 轉換為 Byte 陣列。
/// </summary>
/// <param name="ImgPath">圖片路徑 。</param>
public static byte[] ImageToBuffer(string ImgPath)
{
byte[] _ImageBytes;
if (File.Exists(ImgPath))
{
Image _Image = Image.FromFile(ImgPath);
MemoryStream ms = new MemoryStream();
_Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
_ImageBytes = ms.GetBuffer();
ms.Dispose();
_Image.Dispose();
}
else
{
_ImageBytes = null;
}
return _ImageBytes;
}
沒有留言:
張貼留言