2012-09-24 59 views
0

這裏是網絡攝像頭程序,它可以通過使用void ProcessFrame循環來顯示圖像 如何使用以下代碼獲取光標下方圖像框中的像素數據?如何獲取光標下圖像框中的像素數據?

這裏是我從網站捕獲的代碼。爲幫助

enter code here 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

using Emgu.CV; 
using Emgu.CV.Structure; 
using Emgu.Util; 
using System.Threading; 
namespace MyOpenCV 
{ 
public partial class Form2 : Form 
{ 
    public Form2() 
    { 
     InitializeComponent(); 
    } 

private Capture _capture; 
private bool _captureInProgress; 


private void ProcessFrame(object sender, EventArgs arg) 
{ 
    Image<Bgr, Byte> frame = _capture.QueryFrame(); 
    captureImageBox1.Image = frame; 
} 

private void captureButton_Click_1(object sender, EventArgs e) 
{ 
    #region if capture is not created, create it now 
    if (_capture == null) 
    { 
     try 
     { 
      _capture = new Capture(); 
     } 
     catch (NullReferenceException excpt) 
     { 
      MessageBox.Show(excpt.Message); 
     } 
    } 
    #endregion 

    if (_capture != null) 
    { 
     if (_captureInProgress) 
     { //stop the capture 
      Application.Idle -= new EventHandler(ProcessFrame); 
      captureButton.Text = "Start Capture"; 
     } 
     else 
     { 
      //start the capture 
      captureButton.Text = "Stop"; 
      Application.Idle += new EventHandler(ProcessFrame); 
     } 

     _captureInProgress = !_captureInProgress; 
    } 
} 
+1

不知道我理解你嗎?你想要達到什麼目標? – gideon

+0

我想基於這個代碼..添加一個新的功能,可以顯示光標下的像素數據 –

+0

你是什麼意思,基於此代碼? –

回答

1

非常感謝試試這個:

private void pictureBox1_MouseClick(object sender, MouseEventArgs e) 
     { 
      var bmp = (Bitmap) pictureBox1.Image; 
      var color = bmp.GetPixel(e.X, e.Y); 
     } 
相關問題