前言:
现时朋友们对“c 读取bmp”大约比较讲究,小伙伴们都想要学习一些“c 读取bmp”的相关知识。那么小编也在网摘上搜集了一些对于“c 读取bmp””的相关资讯,希望小伙伴们能喜欢,你们快快来学习一下吧!概述
一般来说winform应用程序解决这个问题起来时很容易的,web应用程序就麻烦一点了。你必要有联机型居民身份证阅读器一个。
实现方式
1、新建一个winform控件项目ReadCardControl,添加一个主类ReadIDCard
private bool ReadIDCard() { try { BLL.API.SynIDCardAPI.IDCardData CardMsg = new BLL.API.SynIDCardAPI.IDCardData(); int nRet, nPort; byte[] pucIIN = new byte[4]; byte[] pucSN = new byte[8]; nPort = Convert.ToInt32(1001); if (BLL.API.SynIDCardAPI.Syn_OpenPort(nPort) == 0) { if (BLL.API.SynIDCardAPI.Syn_SetMaxRFByte(nPort, 80, 0) == 0) { nRet = BLL.API.SynIDCardAPI.Syn_StartFindIDCard(nPort, ref pucIIN[0], 0); nRet = BLL.API.SynIDCardAPI.Syn_SelectIDCard(nPort, ref pucSN[0], 0); nRet = BLL.API.SynIDCardAPI.Syn_ReadMsg(nPort, 0, ref CardMsg); if (nRet == 0) { txtAddress.Text = CardMsg.Address; txtBirthday.Text = CardMsg.Born; txtCerticate.Text = CardMsg.IDCardNo; txtIssuingAuthoriy.Text = CardMsg.GrantDept; txtNames.Text = CardMsg.Name; txtNation.Text = Xw.Common.Helper.NationHelper.GetNationByNO(CardMsg.Nation); txtSex.Text = CardMsg.Sex == "1" ? "男" : "女"; picMan.Image = Image.FromFile(CardMsg.PhotoFileName); //lblMsg.Text = "读卡成功"; return true; } else { lblMsg.Text = "请放卡: 读取身份证信息错误"; return false; } } } else { lblMsg.Text = "打开端口失败"; return false; } return true; } catch (Exception ex) { Xw.Common.Helper.LogHelper.WriteErrorToLog(ex.Message); return false; } }
2、声明DllImport,调用动态链接库
public class SynIDCardAPI { [ ] public struct IDCardData { [//结构中使用的字串,[]类似限定说明 说明此公共结构传输到非托管代码时封装定义 ] public string Name; //姓名 [ ] public string Sex; //性别 [ ] public string Nation; //名族 [ ] public string Born; //出生日期 [ ] public string Address; //住址 [ ] public string IDCardNo; //身份证号 [ ] public string GrantDept; //发证机关 [ ] public string UserLifeBegin; // 有效开始日期 [ ] public string UserLifeEnd; // 有效截止日期 [ ] public string reserved; // 保留 [ ] public string PhotoFileName; // 照片路径 } /************************端口类API *************************/ [ ] public static extern int Syn_SetMaxRFByte(int iPort, byte ucByte, int iIfOpen); [ ] public static extern int Syn_GetCOMBaud(int iPort, ref uint puiBaudRate); [ ] public static extern int Syn_SetCOMBaud(int iPort, uint uiCurrBaud, uint uiSetBaud); [ ] public static extern int Syn_OpenPort(int iPort); [ ] public static extern int Syn_ClosePort(int iPort); /**************************SAM类函数 **************************/ [ ] public static extern int Syn_ResetSAM(int iPort, int iIfOpen); [ ] public static extern int Syn_GetSAMStatus(int iPort, int iIfOpen); [ ] public static extern int Syn_GetSAMID(int iPort, ref byte pucSAMID, int iIfOpen); [ ] public static extern int Syn_GetSAMIDToStr(int iPort, ref byte pcSAMID, int iIfOpen); /*************************身份证卡类函数 ***************************/ [ ] public static extern int Syn_StartFindIDCard(int iPort, ref byte pucIIN, int iIfOpen); [ ] public static extern int Syn_SelectIDCard(int iPort, ref byte pucSN, int iIfOpen); [ ] public static extern int Syn_ReadBaseMsg(int iPort, ref byte pucCHMsg, ref uint puiCHMsgLen, ref byte pucPHMsg, ref uint puiPHMsgLen, int iIfOpen); [ ] public static extern int Syn_ReadIINSNDN(int iPort, ref byte pucIINSNDN, int iIfOpen); [ ] public static extern int Syn_ReadBaseMsgToFile(int iPort, ref byte pcCHMsgFileName, ref uint puiCHMsgFileLen, ref byte pcPHMsgFileName, ref uint puiPHMsgFileLen, int iIfOpen); [ ] public static extern int Syn_ReadIINSNDNToASCII(int iPort, ref byte pucIINSNDN, int iIfOpen); [ ] public static extern int Syn_ReadNewAppMsg(int iPort, ref byte pucAppMsg, ref uint puiAppMsgLen, int iIfOpen); [ ] public static extern int Syn_GetBmp(int iPort, ref byte Wlt_File); [ ] public static extern int Syn_ReadMsg(int iPortID, int iIfOpen, ref IDCardData pIDCardData); [ ] public static extern int Syn_FindReader(); /***********************设置附加功能函数 ************************/ [ ] public static extern int Syn_SetPhotoPath(int iOption, ref byte cPhotoPath); [ ] public static extern int Syn_SetPhotoType(int iType); [ ] public static extern int Syn_SetPhotoName(int iType); [ ] public static extern int Syn_SetSexType(int iType); [ ] public static extern int Syn_SetNationType(int iType); [ ] public static extern int Syn_SetBornType(int iType); [ ] public static extern int Syn_SetUserLifeBType(int iType); [ ] public static extern int Syn_SetUserLifeEType(int iType, int iOption); }
3、读取显示相关的信息
txtAddress.Text = CardMsg.Address; txtBirthday.Text = CardMsg.Born; txtCerticate.Text = CardMsg.IDCardNo; txtIssuingAuthoriy.Text = CardMsg.GrantDept; txtNames.Text = CardMsg.Name; txtNation.Text = Xw.Common.Helper.NationHelper.GetNationByNO(CardMsg.Nation); txtSex.Text = CardMsg.Sex == "1" ? "男" : "女"; picMan.Image = Image.FromFile(CardMsg.PhotoFileName); //lblMsg.Text = "读卡成功"; return true;
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #c 读取bmp