解决新中新身份证读卡器:读取身份证时出错:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
主要是照片被占用引起的,下面代码就OK了
String strImgPath = Application.StartupPath + "\\IDCardImg\\" + readID.IDCardNo + ".jpg"; //注意,系统给的文件名是JPEG,保存的文件是JPG
Image imgCard;
if (System.IO.File.Exists(strImgPath))
{
FileStream fs = new FileStream(strImgPath,
FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader br = new BinaryReader(fs);
MemoryStream stmImg = new MemoryStream(br.ReadBytes((int)fs.Length));
imgCard = Image.FromStream(stmImg);
pnlPicture.BackgroundImage = imgCard;
fs.Close();
}