public void recFace(object pppp) { Bitmap ppp = (Bitmap)pppp; if (label1.InvokeRequired) { label1.Invoke(new System.Threading.ParameterizedThreadStart(recFace), new object[] { pppp }); return; } bool error = false; try { IntPtr ff = ppp.GetHbitmap(); FSDK.LoadImageFromHBitmap(ref cimg, ff); FSDK.SetFaceDetectionParameters(false, false, 500); FSDK.SetFaceDetectionThreshold(1); FSDK.TFacePosition facePosition = new FSDK.TFacePosition(); IntPtr hbitmapHandle = IntPtr.Zero; FSDK.SaveImageToHBitmap(cimg, ref hbitmapHandle); Image ccimg = Image.FromHbitmap(hbitmapHandle); Graphics gr = Graphics.FromImage(ccimg); if (FSDK.FSDKE_OK == FSDK.DetectFace(cimg, ref facePosition)) { gr.DrawRectangle(Pens.LightBlue, facePosition.xc - facePosition.w / 2, facePosition.yc - facePosition.w / 2, facePosition.w, facePosition.w); byte[] tempd = new byte[FSDK.TemplateSize]; FSDK.GetFaceTemplateInRegion(cimg, ref facePosition, out tempd); temp = System.Text.Encoding.ASCII.GetString(tempd); if (check_reg(tempd)) { timer2.Enabled = false; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; gr.DrawString(_name + " | " + _matric + " | " + _room, new System.Drawing.Font("Candara", 18), new System.Drawing.SolidBrush(System.Drawing.Color.LightBlue), facePosition.xc, facePosition.yc + facePosition.w * 0.55f, format); } else { timer2.Enabled = true; } } else { timer2.Enabled = false; label1.Text = "Please Focus on the camera"; } pictureBox1.Height = ccimg.Height; pictureBox1.Width = ccimg.Width; pictureBox1.Image = ccimg; FSDK.FreeImage(cimg); DeleteObject(hbitmapHandle); GC.Collect(); Application.DoEvents(); } catch (NullReferenceException nul) { timer1.Enabled = false; timer1.Dispose(); MessageBox.Show(nul.ToString()); error = true; } catch (ExternalException exer) { } catch (AccessViolationException acs) { } finally { if (error) { canClose = true; Application.Exit(); Application.Restart(); } } }