You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
6.7 KiB
184 lines
6.7 KiB
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
|
|
namespace CameraCard
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private ICameraHelper _cameraHelper = new AForgeCameraHelper();
|
|
|
|
private CVRHelper _cvrHelper = new CVRHelper();
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
this.versionLabel.Alignment = ToolStripItemAlignment.Right;
|
|
this.versionLabel.Text += Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
}
|
|
|
|
private void MainFrom_Load(object sender, EventArgs e)
|
|
{
|
|
//截图
|
|
this.CreateRect();
|
|
//摄像头预览
|
|
this._cameraHelper.OnCameraChange = o =>
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
this.cameraSelector.Items.Clear();
|
|
this.cameraSelector.Text = string.Empty;
|
|
foreach (var item in o)
|
|
{
|
|
this.cameraSelector.Items.Add(item);
|
|
}
|
|
if (this.cameraSelector.Items.Count > 0)
|
|
{
|
|
this.cameraSelector.SelectedIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
this.cameraSelector.Text = "没有检测到USB摄像头";
|
|
}
|
|
}));
|
|
};
|
|
this._cameraHelper.OnFrame = o =>
|
|
{
|
|
cameraRender.Image?.Dispose();
|
|
cameraRender.Image = o;
|
|
};
|
|
this.cameraSelector.SelectedIndexChanged += new EventHandler((s, o) =>
|
|
{
|
|
this._cameraHelper.SwitchCamera((s as ComboBox).SelectedIndex);
|
|
});
|
|
this._cameraHelper.Start();
|
|
//身份读卡器
|
|
this._cvrHelper.OnConnect = new Action<bool>(o =>
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
this.statusLabel.Text = o ? "读卡器已连接" : "读卡器未连接";
|
|
}));
|
|
});
|
|
this._cvrHelper.OnRead = new Action<IdCardModel>(o =>
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
this.UpdateIdCardUI(o);
|
|
}));
|
|
});
|
|
this._cvrHelper.Start();
|
|
}
|
|
|
|
private void cameraSelector_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
this._cameraHelper.SwitchCamera(this.cameraSelector.SelectedIndex);
|
|
}
|
|
|
|
private int _rectWidth = 351;
|
|
private int _rectHeight = 448;
|
|
private int _photoWidth;
|
|
private int _photoHeight;
|
|
private Rectangle _rect;
|
|
private Pen _pen;
|
|
|
|
private void CreateRect()
|
|
{
|
|
this._photoWidth = 351;
|
|
this._photoHeight = 448;
|
|
this._rectWidth = this._photoWidth / 2;
|
|
this._rectHeight = this._photoHeight / 2;
|
|
//
|
|
var x = this.cameraRender.Width / 2 - this._rectWidth / 2;
|
|
var y = this.cameraRender.Height / 2 - this._rectHeight / 2;
|
|
this._rect = new Rectangle(x, y, _rectWidth, _rectHeight);
|
|
this._pen = new Pen(Color.Green);
|
|
this._pen.DashStyle = DashStyle.Dash;
|
|
}
|
|
|
|
private void cameraRender_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
e.Graphics.DrawRectangle(this._pen, _rect);
|
|
}
|
|
|
|
private void shotBtn_Click(object sender, EventArgs e)
|
|
{
|
|
using (var bitmap = (this.cameraRender.Image.Clone() as Image))
|
|
{
|
|
using (var bitmap2 = bitmap.ClipImage(this.cameraRender.Width, this.cameraRender.Height, this._rectWidth, this._rectHeight))
|
|
{
|
|
this.photo.Image?.Dispose();
|
|
this.photo.Image = bitmap2.ResizeImage(this._photoWidth, this._photoHeight);
|
|
var base64Value = $"data:image/jpeg;base64,{this.photo.Image.ToBase64()}";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateIdCardUI(IdCardModel model)
|
|
{
|
|
this.idcPicture.Image?.Dispose();
|
|
this.idcPicture.Image = model.Image;
|
|
if (model.Type == "居民身份证")
|
|
{
|
|
this.idcAddressLabel.Visible = true;
|
|
this.idcAddressValue.Visible = true;
|
|
this.idcCnNameLabel.Visible = false;
|
|
this.idcCnNameValue.Visible = false;
|
|
this.idcAddressLabel.Visible = true;
|
|
this.idcAddressValue.Visible = true;
|
|
this.idcAddressValue.Text = model.Address;
|
|
this.idcNameLable.Text = "民族:";
|
|
this.idcNationCodeLabel.Text = "民族代码:";
|
|
this.idcIdCardNoLabel.Text = "身份证号";
|
|
}
|
|
else
|
|
{
|
|
this.idcAddressLabel.Visible = false;
|
|
this.idcAddressValue.Visible = false;
|
|
this.idcCnNameLabel.Visible = true;
|
|
this.idcCnNameValue.Visible = true;
|
|
this.idcAddressLabel.Visible = false;
|
|
this.idcAddressValue.Visible = false;
|
|
this.idcCnNameValue.Text = model.CnName;
|
|
this.idcNameLable.Text = "国籍:";
|
|
this.idcNationCodeLabel.Text = "国籍代码:";
|
|
this.idcIdCardNoLabel.Text = "证件号码";
|
|
}
|
|
this.idcNameValue.Text = model.Name;
|
|
this.idcSexValue.Text = model.Sex;
|
|
this.idcNationValue.Text = model.Nation;
|
|
this.idcNationCodeValue.Text = model.NationCode;
|
|
this.idcBirthdayValue.Text = model.Birthday;
|
|
this.idcIdCardNoValue.Text = model.IdCardNo;
|
|
this.idcDepartmentValue.Text = model.Department;
|
|
this.idcValidDateValue.Text = $"{model.ValidDateStart}-{model.ValidDateEnd}";
|
|
this.idcSamIDValue.Text = model.SamID;
|
|
}
|
|
|
|
private void checkUpdate_Click(object sender, EventArgs e)
|
|
{
|
|
var file = Path.Combine(Application.StartupPath, "AutoUpdate.exe");
|
|
var file2 = Path.Combine(Application.StartupPath, "update.exe");
|
|
File.Copy(file, file2, true);
|
|
var info = new ProcessStartInfo
|
|
{
|
|
FileName = file2,
|
|
Arguments = Application.ExecutablePath,
|
|
WorkingDirectory = Application.StartupPath
|
|
};
|
|
Process.Start(info);
|
|
}
|
|
|
|
//closeing
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
this._cameraHelper.Dispose();
|
|
this._pen.Dispose();
|
|
}
|
|
}
|
|
} |