/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); if (bPluginLoaded) { freeframe.deInstantiate(instanceID); freeframe.Dispose(); } if (webcam != null) { webcam.Dispose(); webcam = null; } if (video != null) { video.Dispose(); video = null; } }
private void FormWebCamm_FormClosing(object sender, FormClosingEventArgs e) { try { WebCam.Stop(); WebCam.Dispose(); WebCam = null; } catch (Exception) { } }
/// <summary> /// 點選透過WebCam照像的動作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnCam_Click(object sender, EventArgs e) { // 打開WebCam oWebCam = new WebCam(); oWebCam.Container = picImage; oWebCam.Container.Height = picImage.Height; oWebCam.Container.Width = picImage.Width; oWebCam.OpenConnection(); Image img = oWebCam.CaptureImage(); picImage.Image = img; MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); oWebCam.Dispose(); HttpResponseMessage response = await new CognitiveUtility().FaceDetect(ms, base.SetupConfig.FaceApiKey); string strContent = await response.Content.ReadAsStringAsync(); Face[] faces = JsonConvert.DeserializeObject <Face[]>(strContent); await this.DetectFace(faces); }
/// <summary> /// 點選停止的動作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStop_Click(object sender, EventArgs e) { tiCapture.Enabled = false; oWebCam.Dispose(); }