2016-03-19 7 views
-1

Ich habe einen Code geschrieben Bild erfassen 0 einen Eingang geben scheint, den Bildes.Verfahren Code erfassen zu laufen, aber es erfaßt kein Bild bei bestimmtem Eingang .Ich bin nicht in der Lage Bild in Fensterform Anwendung zu erfassen mit C# -Code

Im Folgenden ist der Code

'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 ist die Taste, um das Bild zu erfassen

 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); 
    } 

// picCap_Click ist das Bildfeld, wo das Bild

erhalten gefangen müssen
private void picCap_Click(object sender, EventArgs e) 
    { 

    } 

} 
}' 

Ausnahmedetails: Null Reference Exception erzeugt

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

Sind Sie irgendeine Ausnahme bekommen? – VVN

+0

Ja, es gibt eine Null-Referenz-Ausnahme. Aber ich habe versucht, die Ausnahme gefangen ... sollte das den Bug nicht lösen? –

+0

Nun, schließen wir das - Oswald, zögern Sie nicht, die Frage zu stellen, wenn Sie den Regeln der Website folgen können. Was beinhaltet einen vollständigen Fehlerbericht. Welche enthält Fehlerdetails. Wenn Sie nicht genug C# haben, dann müssen Sie anfangen, wirklich grundlegendes Lernen zu machen. – TomTom

Antwort

0

möglich reson ist, dass Ihre Webcam ist null Hexe gibt diese Ausnahme: WebCam Webcam;

try tun Webcam Webcam = new Webcam(); auch in nessecary Argumente :)

leider meine erste answear aber NULL-Verweis wird ausgelöst, wenn Sie versuchen, etwas zu verwenden, die null Hexe Web-Cam ist becouse seine nicht auf etwas gesetzt hoffe das hilft dir =)

+0

Ich habe es bereits in der MainWinForm_Load() -Funktion bereitgestellt –

Verwandte Themen