private void button1_Click_1(object sender, EventArgs e) { TwoIdInfoStruct info = ReadCard.ReadCardNo(); lblAddress.Text = Encoding.Unicode.GetString(info.arrTwoIdAddress); lblSex.Text = Encoding.Unicode.GetString(info.arrTwoIdSex); lblBirthday.Text = Encoding.Unicode.GetString(info.arrTwoIdBirthday); lblDept.Text = Encoding.Unicode.GetString(info.arrTwoIdSignedDepartment); lblIdCard.Text = Encoding.Unicode.GetString(info.arrTwoIdNo); lblName.Text = Encoding.Unicode.GetString(info.arrTwoIdName); lblNation.Text = Encoding.Unicode.GetString(info.arrTwoIdNation); lblValidDate.Text = Encoding.Unicode.GetString(info.arrTwoIdValidityPeriodBegin) + "-" + Encoding.Unicode.GetString(info.arrTwoIdValidityPeriodEnd); byte[] dstImage = new byte[50 * 1024]; int outlen = 1024 * 50; if (ReadCard.decodeImage(info.arrTwoIdPhoto, dstImage, ref outlen)) { MessageBox.Show("图片解码成功"); MemoryStream ms = new MemoryStream(dstImage); Image image = System.Drawing.Image.FromStream(ms); pictureBox1.Image = image; } }
public static TwoIdInfoStruct ReadCardNo() { TwoIdInfoStruct sttTwoIdInfo = new TwoIdInfoStruct(); sttTwoIdInfo.arrTwoIdName = new byte[30]; //姓名 UNICODE sttTwoIdInfo.arrTwoIdSex = new byte[2]; //性别 UNICODE sttTwoIdInfo.arrTwoIdNation = new byte[4]; //民族 UNICODE sttTwoIdInfo.arrTwoIdBirthday = new byte[16]; //出生日期 UNICODE YYYYMMDD sttTwoIdInfo.arrTwoIdAddress = new byte[70]; //住址 UNICODE sttTwoIdInfo.arrTwoIdNo = new byte[36]; //身份证号码 UNICODE sttTwoIdInfo.arrTwoIdSignedDepartment = new byte[30]; //签发机关 UNICODE sttTwoIdInfo.arrTwoIdValidityPeriodBegin = new byte[16]; //有效期起始日期 UNICODE YYYYMMDD sttTwoIdInfo.arrTwoIdValidityPeriodEnd = new byte[16]; //有效期截止日期 UNICODE YYYYMMDD 有效期为长期时存储“长期” sttTwoIdInfo.arrTwoOtherNO = new byte[18]; sttTwoIdInfo.arrTwoSignNum = new byte[4]; sttTwoIdInfo.arrTwoRemark1 = new byte[6]; sttTwoIdInfo.arrTwoType = new byte[2]; sttTwoIdInfo.arrTwoRemark2 = new byte[6]; sttTwoIdInfo.arrTwoIdNewAddress = new byte[70]; //最新住址 UNICODE sttTwoIdInfo.arrReserve = new byte[2]; //最新住址 UNICODE sttTwoIdInfo.arrTwoIdPhoto = new byte[1024]; //照片信息 sttTwoIdInfo.arrTwoIdFingerprint = new byte[1024]; //指纹信息 sttTwoIdInfo.arrTwoIdPhotoJpeg = new byte[4096]; //照片信息 JPEG 格式 sttTwoIdInfo.unTwoIdPhotoJpegLength = 0; //照片信息长度 JPEG格式 int hlHandle = cardOpenDevice(5, 0); if (hlHandle > 0) { bool bmove = true; if (setCardType(hlHandle, 1)) { if (cardFindCard(hlHandle, ref bmove)) { int cb = 0; string szAppkey = "99ffb2f98a29071107c7a09ad2c6d096"; string szip = "id.yzfuture.cn"; bool bret = cardReadTwoCard(hlHandle, cb, szAppkey, szip, 8848, ref sttTwoIdInfo, false); if (bret) { MessageBox.Show("解码成功:" + Encoding.Unicode.GetString(sttTwoIdInfo.arrTwoIdName)); MessageBox.Show("身份证号:" + Encoding.Unicode.GetString(sttTwoIdInfo.arrTwoIdNo)); } } } cardCloseDevice(hlHandle); } return(sttTwoIdInfo); }
CallingConvention = CallingConvention.StdCall)] //readCardInfo.dll public static extern bool cardReadTwoCard(int nDeviceHandle, int cardCB, string szFactoryFlag, string szServerIp, int nServerPort, ref TwoIdInfoStruct cardinfo, bool bTest); //读卡