2016-02-27 171 views
0

我一直在研究生成和读取(解码)QR码的应用程序。在解码部分,用户捕获QR码的图片,程序将开始解码过程。 我的问题是我不知道如何拍照。 P.S: 如果您提供库,请提供一个链接,其中包含使用该库的教程。 谢谢。从c摄像头捕获图像#

+1

对于SO的图书馆建议是无题的,请尝试在网上搜索“C#library webcam capture”。 – CodeCaster

+0

我已经搜索,但找不到教程 –

+3

@ A.Hajeb至少选择一些图书馆,尝试使用它,如果遇到任何困难,请创建一个关于如何使用该特定图书馆的具体问题。 –

回答

0

我一直在寻找网络摄像机录音很长一段时间,你可以使用Aforge.NET。

下面是使用相同的代码WPF:

public partial class MainWindow : Window 
    { 
     private FilterInfoCollection VideoCaptureDevices; 
     private VideoCaptureDevice FinalVideo; 
     public VideoFileWriter writer= new VideoFileWriter(); 

     public MainWindow() 
     { 
      InitializeComponent(); 

      VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); 
      foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices) 
      { 
       comboBox1.Items.Add(VideoCaptureDevice.Name); 
      } 
      comboBox1.SelectedIndex = 0; 


     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      writer.Open(@"d:\\newVid.avi", 640, 480, 25, VideoCodec.MPEG4); 

      FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString); 
      FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); 
      FinalVideo.Start(); 

     } 

     void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) 
     { 

      System.Drawing.Image imgforms = (Bitmap)eventArgs.Frame.Clone(); 

      Bitmap bmp = (Bitmap)eventArgs.Frame.Clone(); 

      BitmapImage bi = new BitmapImage(); 
      bi.BeginInit(); 

      MemoryStream ms = new MemoryStream(); 
      imgforms.Save(ms, ImageFormat.Bmp); 
      ms.Seek(0, SeekOrigin.Begin); 

      bi.StreamSource = ms; 
      bi.EndInit();    

      //Using the freeze function to avoid cross thread operations 
      bi.Freeze(); 

      //Calling the UI thread using the Dispatcher to update the 'Image' WPF control   
      Dispatcher.BeginInvoke(new ThreadStart(delegate 
      { 
       pictureBox1.Source = bi; /*frameholder is the name of the 'Image' WPF control*/ 
      })); 

      for (int i = 0; i < 2; i++) 
      { 
       writer.WriteVideoFrame(bmp); 
      } 

     } 

     private void Stop_Click(object sender, RoutedEventArgs e) 
     { 
      writer.Close(); 
      FinalVideo.Stop(); 
      this.Close(); 
     } 

    } 

包括以下命名空间:

using AForge.Video; 
using AForge.Video.DirectShow; 
using AForge.Video.FFMPEG; 
using System.Drawing.Drawing2D; 
using AForge.Video.VFW; 

您可以设置变化的帧速率,按您的方便。

+0

是否拍摄照片或拍摄视频? –

+0

它捕获的视频,但正如你可以在代码中看到有图像被添加在框架中。你可以选择任何图像。 –

+0

VS无法识别“BitmapImage bi = new BitmapImage();” –