# 影像處理

參考資料:Bitmap(<https://msdn.microsoft.com/zh-tw/library/system.drawing.bitmap(v=vs.110).aspx>)

## BitmapToByte

參考資料:(<http://blog.udn.com/yccsonar/28112333>)

額外參考資料:(<https://stackoverflow.com/questions/7350679/convert-a-bitmap-into-a-byte-array>)

```
     byte[] content;
     System.Drawing.Bitmap srcImage = new System.Drawing.Bitmap(ImgPath + ImgName);
     MemoryStream ms = new MemoryStream();
     srcImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
     content = ms.GetBuffer();
```

## 在GDI+ 中發生泛型錯誤

參考資料:(<https://blog.miniasp.com/post/2009/05/30/A-generic-error-occurred-in-GDI-plus.aspx>)

### 跟C#語法無關

#### 與檔案系統相關

確認目錄權限，是否無法寫入、無法讀取。

確認檔案權限，是否無法寫入、無法讀取。

目錄是否存在。

#### 與圖檔格式相關

無法轉換的圖檔類型

透過Image.FromStream 載入圖片時無法使用Seek方法

輸入的編碼有問題。
