2013-03-14 73 views
0

我正在編寫一個使用網絡攝像頭捕獲圖像的C#程序。 對於輸出圖像的方框,選擇imagebox(在EmguCV庫中)。 我願意從輸出圖像中獲取像素信息。 根據我的發現,我需要將imagebox中的圖像轉換爲位圖,然後我可以在c#中使用picturebox執行分析 (http://www.emgu.com/wiki/index.php/Working_with_Images#Using_ImageBox) 因此,需要Tobitmap()方法。任何人都可以給我想法如何將圖像盒圖像轉換爲位圖的基礎上的功能? 非常感謝Imagebox轉換爲位圖

private void ProcessFrame(object sender, EventArgs arg) 
{ 
    ImageFrame = _capture.QueryFrame(); 
    detectimageBox.Image = ImageFrame; 
} 

回答

1

只是通過圖像轉換成位圖的構造函數:

Bitmap bitmap = new Bitmap(detectImageBox.Image); 

你可以,當然,創建擴展:

public static Bitmap ToBitmap(this PictureBox imageBox) 
    { 
     return new Bitmap(imageBox.Image) 
    } 

這樣稱呼它:

Bitmap bitmap = detectImageBox.ToBitmap(); 

N注意:我沒有做任何空檢查或任何東西,我建議你加入他們。

+0

這不是鑄造 - 創建一個新的位圖實例。 – Igor 2013-03-14 14:07:47

+0

不知道我爲什麼使用這個術語。我覺得很累。編輯後。 – 2013-03-14 14:09:13

+0

感謝讓我試試:) – user1994617 2013-03-14 14:11:00