How to execute device camera from main form to another form using Aforge direct show in C#? -
i have problem in executing device main form form use combo box select device, after select device main form click button open form, form has button start when click it, should start run camera without selecting device anymore because did in main form got exception saying.
"object reference not set instance of object."
this code other form.
private void start_click_1(object sender, eventargs e) { if (start.text == "&start") { if (deviceexist) { frmmain cam = new frmmain(); videosource = new videocapturedevice(videodevices[cam.combobox1.selectedindex].monikerstring); // exception shows here! videosource.newframe += new newframeeventhandler(video_newframe); closevideosource(); videosource.desiredframesize = new size(160, 120); //videosource.desiredframerate = 10; videosource.start(); lblstat.text = "device running..."; start.text = "&stop"; } } }
what think problem here?
frmmain cam = new frmmain(); videosource = new videocapturedevice(videodevices[cam.combobox1.selectedindex].monikerstring);
you create new instance of frmmain
cam = new frmmain()
, access cam.combobox1.selectedindex
default -1. causes error
Comments
Post a Comment