Advertisement
Guest User

Untitled

a guest
Oct 4th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1.     public partial class Form1 : Form
  2.     {
  3.         private Image<Bgr, Byte> imgStat = null;
  4.         private Capture capture = null;
  5.         private bool _captureInProgress = false;
  6.      //   private bool captureInProgress;
  7.  
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.             imgStat = null;
  12.          }
  13.  
  14.         public string selectFile()
  15.         {
  16.             OpenFileDialog ofd = new OpenFileDialog();
  17.             ofd.ShowDialog();
  18.             String s = ofd.FileName.Normalize();
  19.             return s;
  20.         }
  21.          
  22.         private void button2_Click(object sender, EventArgs e)
  23.         {
  24.             Capture capture = new Capture(selectFile());                    
  25.             capture.ImageGrabbed += ProcessFrame;
  26.             capture.Start();
  27.         }
  28.  
  29.         private void ProcessFrame(object sender, EventArgs e)
  30.         {
  31.             try
  32.             {
  33.                 //capture.Grab(); //doesnt help
  34.                // Image<Bgr, byte> beeldje = capture.QueryFrame(); //doesnt work as well
  35.                 Image<Bgr, byte> beeldje = capture.RetrieveBgrFrame();
  36.                
  37.                     DisplayImage(beeldje.ToBitmap());
  38.             }
  39.             catch (Exception er)
  40.             {
  41.                Console.WriteLine(er.Message);
  42.             }
  43.         }
  44.  
  45.          private delegate void DisplayImageDelegate(Bitmap Image);
  46.          private void DisplayImage(Bitmap Image)
  47.          {
  48.              if (pictureBox1.InvokeRequired)
  49.              {
  50.                  try
  51.                  {
  52.                      DisplayImageDelegate DI = new DisplayImageDelegate(DisplayImage);
  53.                      this.BeginInvoke(DI, new object[] {Image});
  54.                  }
  55.                  catch (Exception ex)
  56.                  {
  57.                  }
  58.              }
  59.              else
  60.              {
  61.                  pictureBox1.Image = Image;
  62.              }
  63.          }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement