diff --git a/ICS/CardReader.cs b/ICS/CardReader.cs index 9ea7269..78927c6 100644 --- a/ICS/CardReader.cs +++ b/ICS/CardReader.cs @@ -98,7 +98,8 @@ fs.Close(); int img = GetBmp(path, 2); - string faceImageLoadPath = path0 + ".bmp"; + // string faceImageLoadPath = path0 + ".bmp"; + string faceImageLoadPath = Application.StartupPath + "\\TEMP"; // 将身份证的照片存入TEMP目录 ImageFormat faceImageLoadFormat = ImageFormat.Bmp; Image ph =Image.FromFile(faceImageLoadPath); diff --git a/ICS/CardReader.cs b/ICS/CardReader.cs index 9ea7269..78927c6 100644 --- a/ICS/CardReader.cs +++ b/ICS/CardReader.cs @@ -98,7 +98,8 @@ fs.Close(); int img = GetBmp(path, 2); - string faceImageLoadPath = path0 + ".bmp"; + // string faceImageLoadPath = path0 + ".bmp"; + string faceImageLoadPath = Application.StartupPath + "\\TEMP"; // 将身份证的照片存入TEMP目录 ImageFormat faceImageLoadFormat = ImageFormat.Bmp; Image ph =Image.FromFile(faceImageLoadPath); diff --git a/ICS/FaceCaptureForm.Designer.cs b/ICS/FaceCaptureForm.Designer.cs index 8ed6b23..e022daa 100644 --- a/ICS/FaceCaptureForm.Designer.cs +++ b/ICS/FaceCaptureForm.Designer.cs @@ -30,6 +30,7 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FaceCaptureForm)); this.videoPlayer = new AForge.Controls.VideoSourcePlayer(); + this.btn_capture = new System.Windows.Forms.Button(); this.SuspendLayout(); // // videoPlayer @@ -42,12 +43,25 @@ this.videoPlayer.TabIndex = 4; this.videoPlayer.VideoSource = null; // + // btn_capture + // + this.btn_capture.AutoSize = true; + this.btn_capture.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); + this.btn_capture.Location = new System.Drawing.Point(46, 138); + this.btn_capture.Name = "btn_capture"; + this.btn_capture.Size = new System.Drawing.Size(75, 27); + this.btn_capture.TabIndex = 5; + this.btn_capture.Text = "拍照"; + this.btn_capture.UseVisualStyleBackColor = true; + this.btn_capture.Click += new System.EventHandler(this.btn_capture_Click); + // // FaceCaptureForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(184, 161); this.ControlBox = false; + this.Controls.Add(this.btn_capture); this.Controls.Add(this.videoPlayer); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; @@ -57,10 +71,12 @@ this.Text = "拍照"; this.TopMost = true; this.ResumeLayout(false); + this.PerformLayout(); } #endregion private AForge.Controls.VideoSourcePlayer videoPlayer; + private System.Windows.Forms.Button btn_capture; } } \ No newline at end of file diff --git a/ICS/CardReader.cs b/ICS/CardReader.cs index 9ea7269..78927c6 100644 --- a/ICS/CardReader.cs +++ b/ICS/CardReader.cs @@ -98,7 +98,8 @@ fs.Close(); int img = GetBmp(path, 2); - string faceImageLoadPath = path0 + ".bmp"; + // string faceImageLoadPath = path0 + ".bmp"; + string faceImageLoadPath = Application.StartupPath + "\\TEMP"; // 将身份证的照片存入TEMP目录 ImageFormat faceImageLoadFormat = ImageFormat.Bmp; Image ph =Image.FromFile(faceImageLoadPath); diff --git a/ICS/FaceCaptureForm.Designer.cs b/ICS/FaceCaptureForm.Designer.cs index 8ed6b23..e022daa 100644 --- a/ICS/FaceCaptureForm.Designer.cs +++ b/ICS/FaceCaptureForm.Designer.cs @@ -30,6 +30,7 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FaceCaptureForm)); this.videoPlayer = new AForge.Controls.VideoSourcePlayer(); + this.btn_capture = new System.Windows.Forms.Button(); this.SuspendLayout(); // // videoPlayer @@ -42,12 +43,25 @@ this.videoPlayer.TabIndex = 4; this.videoPlayer.VideoSource = null; // + // btn_capture + // + this.btn_capture.AutoSize = true; + this.btn_capture.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); + this.btn_capture.Location = new System.Drawing.Point(46, 138); + this.btn_capture.Name = "btn_capture"; + this.btn_capture.Size = new System.Drawing.Size(75, 27); + this.btn_capture.TabIndex = 5; + this.btn_capture.Text = "拍照"; + this.btn_capture.UseVisualStyleBackColor = true; + this.btn_capture.Click += new System.EventHandler(this.btn_capture_Click); + // // FaceCaptureForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(184, 161); this.ControlBox = false; + this.Controls.Add(this.btn_capture); this.Controls.Add(this.videoPlayer); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; @@ -57,10 +71,12 @@ this.Text = "拍照"; this.TopMost = true; this.ResumeLayout(false); + this.PerformLayout(); } #endregion private AForge.Controls.VideoSourcePlayer videoPlayer; + private System.Windows.Forms.Button btn_capture; } } \ No newline at end of file diff --git a/ICS/FaceCaptureForm.cs b/ICS/FaceCaptureForm.cs index adede09..e4ef001 100644 --- a/ICS/FaceCaptureForm.cs +++ b/ICS/FaceCaptureForm.cs @@ -2,6 +2,7 @@ using AForge.Video.DirectShow; using System; using System.Drawing; +using System.IO; using System.Windows.Forms; namespace ICS @@ -29,6 +30,10 @@ videoPlayer.Height = height; videoPlayer.Left = 0; videoPlayer.Top = 0; + + // 拍照按钮摆放在最下面 + btn_capture.Left = (width - btn_capture.Size.Width) / 2; + btn_capture.Top = height - btn_capture.Size.Height - (this.Height - this.ClientRectangle.Height); // 考虑标题栏的高度 } // 注册相机拍摄事件 @@ -54,5 +59,27 @@ { return videoPlayer.GetCurrentVideoFrame(); } + + // 手动拍照 + private void btn_capture_Click(object sender, EventArgs e) + { + Bitmap bmpImg = videoPlayer.GetCurrentVideoFrame(); + + if (null != bmpImg) + { + long now = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; + string yearMonth = DateTime.Now.ToString("yyyyMM"); + string dirPath = AppDomain.CurrentDomain.BaseDirectory + "pic\\" + yearMonth; + if (Directory.Exists(dirPath) == false) + { + // 如果不存在则新建一个文件夹 + Directory.CreateDirectory(dirPath); + } + string path = dirPath + "\\" + now + ".bmp"; + bmpImg.Save(path, System.Drawing.Imaging.ImageFormat.Bmp); + + MessageBox.Show("手动拍照成功。\r\n文件名:" + path); + } + } } }