2016-03-19 10 views
-1

Görüntüyü yakalamak için 0 girişi veren görüntüyü yakalamak için bir kod yazdım. Kod çalışıyormuş gibi görünüyor ancak verilen herhangi bir görüntüyü yakalamıyor .C# kodu kullanarak pencere formu uygulamasında görüntü yakalayamıyorum

takiben kodu olan

'using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Drawing.Imaging; 
    using System.Linq; 
    using System.Text; 
    using System.Windows.Forms; 

    namespace WindowsFormsApplication3 
    { 
    public partial class mainWinForm :Form 
    {    
     public mainWinForm() 
     { 
     InitializeComponent(); 
     } 
     WebCam webcam; 

// button2_Click image

 private void button2_Click(object sender, EventArgs e) 
    { 
     int a = Convert.ToInt32(textBox1.Text);//textbox to give i/p 
     Console.WriteLine(a); 

     try 
     { 


      if (a == 0) 
      { 
       webcam.Start(); 
       picCap.Image.Save(@"C:\Users\Administrator\Desktop\temp\MyImage.jpg", ImageFormat.Jpeg); 

      } 
      else 
      { 
       MessageBox.Show("Wrong input"); 

      } 

      webcam.Stop(); 
     } 
     catch (NullReferenceException) 
     { 
      return; 
     }    
    } 

    private void mainWinForm_Load(object sender, EventArgs e) 
    { 
     webcam = new WebCam(); 
     webcam.InitializeWebCam(ref picCap); 
    } 
yakalamak için düğme

// picCap_Click görüntü tutuklanabilirim gerekir resim kutusudur

private void picCap_Click(object sender, EventArgs e) 
    { 

    } 

} 
}' 

Özel durum ayrıntıları: null başvuru İstisna

oluşturulan
System.NullReferenceException was unhandled 
HResult=-2147467261 
Message=Object reference not set to an instance of an object. 
Source=WindowsFormsApplication3 
StackTrace: 
    at WindowsFormsApplication3.mainWinForm.button2_Click(Object sender, EventArgs e) in C:\Users\Administrator\documents\visual studio 2010\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs:line 49 
    at System.Windows.Forms.Control.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
    at System.Windows.Forms.Button.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
    at System.Windows.Forms.Application.Run(Form mainForm) 
    at WindowsFormsApplication3.Program.Main() in C:\Users\Administrator\documents\visual studio 2010\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Program.cs:line 18 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 
InnerException: 
+0

misiniz herhangi bir istisna almak? – VVN

+0

evet boş bir referans istisnası var.Ama istisnayı yakalamayı denedim ... hatayı çözmemeli miydi? –

+0

Peki, bunu kapatalım - Oswald, site kurallarını takip edebileceğiniz zaman soruyu sormakta özgürsünüz. Hangi bir Tam Hata Raporu içerir. Hangi hata ayrıntılarını içerir. Yeterli C# yoksa, gerçekten bazı temel öğrenmeye başlamak gerekir. – TomTom

cevap

0

mümkün tınlama web kameranızı boş cadı olduğuna istisna sağlamasıdır: WebCam kamerası;

web kamerası yapmayı deneyin webcam = new webcam(); Ayrıca nessecary argümanlar :) koymak

) = Eğer onun hiçbir şeye ayarlı değil bu size yardımcı olur umarım nedeniyle bu derste boş cadı web cam olan bir şey kullanmaya çalıştığınızda ilk answear ama null başvuru atılır

üzgün

+0

Bunu mainWinForm_Load() işlevinde zaten sağladım –