读取二代身份证上的相片,函数GetBmp(char * Wlt_File,int intf) 怎么用?
2010-07-06 13:12
1296 查看
今天看到很多网友对于读取二代身份证上的相片遇到了麻烦,GetBmp(char * Wlt_File,int intf) 这个函数不知道怎么用。下面是我做的小实例,仅供参考,希望能帮到大家。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region API声明
[DllImport("sdtapi.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SDT_StartFindIDCard (int iPort, byte[] pucManaInfo,int iIfOpen);
[DllImport("sdtapi.dll",CallingConvention = CallingConvention.StdCall)]
static extern int SDT_SelectIDCard (int iPort , byte[] pucManaMsg,int iIfOpen);
[DllImport("sdtapi.dll",CallingConvention = CallingConvention.StdCall)]
static extern int SDT_ReadBaseMsg (int iPort, byte[] pucCHMsg, ref UInt32 puiCHMsgLen, byte[] pucPHMsg,ref UInt32 puiPHMsgLen,int iIfOpen);
[DllImport("WltRS.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetBmp(string pucPHMsg, int intf);
#endregion
byte[] pucPHMsg = new byte[3024];
//读卡操作按钮事件
private void button1_Click(object sender, EventArgs e)
{
//变量声明
byte[] CardPUCIIN = new byte[255];
byte[] pucManaMsg = new byte[255];
byte[] pucCHMsg = new byte[255];
UInt32 puiCHMsgLen = 0;
UInt32 puiPHMsgLen = 0;
int st = 0;
//读卡操作
st = SDT_StartFindIDCard(1001, CardPUCIIN, 1);
if (st != 0x9f) return;
st = SDT_SelectIDCard(1001, pucManaMsg, 1);
if (st != 0x90) return;
st = SDT_ReadBaseMsg(1001, pucCHMsg, ref puiCHMsgLen, pucPHMsg, ref puiPHMsgLen, 1);
if (st != 0x90) return;
//显示结果
textBox1.Text = System.Text.ASCIIEncoding.Unicode.GetString(pucCHMsg);
}
//照片保存按钮事件
private void button2_Click(object sender, EventArgs e)
{
FolderDialog fDialog = new FolderDialog();
fDialog.DisplayDialog();
string path = fDialog.Path + @"/" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".wlt";
File.Delete(path);
FileStream fs = File.Open(path, FileMode.Append);
fs.Write(pucPHMsg, 0, pucPHMsg.Length);
fs.Close();
int img = GetBmp(fDialog.Path + @"/" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".wlt", 2);
}
}
说明:照片的信息其实是保存在pucPHMsg变量里面的,需要做的就是将pucPHMsg变量中的照片信息先转换为.wlt文件,再通过GetBmp函数将其转成Bmp文件即可。
三、函数列表
GetBmp(char * Wlt_File,int intf) wlt文件解码成bmp文件;
四、函数说明
原 型:int GetBmp(char * Wlt_File,int intf);
说 明:本函数用于将wlt文件解码成bmp文件。
参 数:Wlt_File ----- wlt文件名
intf ----- 阅读设备通讯接口类型(1—RS-232C,2—USB)
返 回 值:生成*.bmp文件和以下返回信息
值 意义
1 相片解码解码正确
0 调用sdtapi.dll错误
-1 相片解码错误
-2 wlt文件后缀错误
-3 wlt文件打开错误
-4 wlt文件格式错误
-5 软件未授权
-6 设备连接错误
五、注意事项
1、 wlt文件的后缀要固定为”.wlt”,如:xp.wlt,相片解码成xp.bmp;
2、 本函数要与sdtapi.dll关联使用,并确认通讯端口处于关闭状态;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region API声明
[DllImport("sdtapi.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SDT_StartFindIDCard (int iPort, byte[] pucManaInfo,int iIfOpen);
[DllImport("sdtapi.dll",CallingConvention = CallingConvention.StdCall)]
static extern int SDT_SelectIDCard (int iPort , byte[] pucManaMsg,int iIfOpen);
[DllImport("sdtapi.dll",CallingConvention = CallingConvention.StdCall)]
static extern int SDT_ReadBaseMsg (int iPort, byte[] pucCHMsg, ref UInt32 puiCHMsgLen, byte[] pucPHMsg,ref UInt32 puiPHMsgLen,int iIfOpen);
[DllImport("WltRS.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetBmp(string pucPHMsg, int intf);
#endregion
byte[] pucPHMsg = new byte[3024];
//读卡操作按钮事件
private void button1_Click(object sender, EventArgs e)
{
//变量声明
byte[] CardPUCIIN = new byte[255];
byte[] pucManaMsg = new byte[255];
byte[] pucCHMsg = new byte[255];
UInt32 puiCHMsgLen = 0;
UInt32 puiPHMsgLen = 0;
int st = 0;
//读卡操作
st = SDT_StartFindIDCard(1001, CardPUCIIN, 1);
if (st != 0x9f) return;
st = SDT_SelectIDCard(1001, pucManaMsg, 1);
if (st != 0x90) return;
st = SDT_ReadBaseMsg(1001, pucCHMsg, ref puiCHMsgLen, pucPHMsg, ref puiPHMsgLen, 1);
if (st != 0x90) return;
//显示结果
textBox1.Text = System.Text.ASCIIEncoding.Unicode.GetString(pucCHMsg);
}
//照片保存按钮事件
private void button2_Click(object sender, EventArgs e)
{
FolderDialog fDialog = new FolderDialog();
fDialog.DisplayDialog();
string path = fDialog.Path + @"/" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".wlt";
File.Delete(path);
FileStream fs = File.Open(path, FileMode.Append);
fs.Write(pucPHMsg, 0, pucPHMsg.Length);
fs.Close();
int img = GetBmp(fDialog.Path + @"/" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".wlt", 2);
}
}
说明:照片的信息其实是保存在pucPHMsg变量里面的,需要做的就是将pucPHMsg变量中的照片信息先转换为.wlt文件,再通过GetBmp函数将其转成Bmp文件即可。
三、函数列表
GetBmp(char * Wlt_File,int intf) wlt文件解码成bmp文件;
四、函数说明
原 型:int GetBmp(char * Wlt_File,int intf);
说 明:本函数用于将wlt文件解码成bmp文件。
参 数:Wlt_File ----- wlt文件名
intf ----- 阅读设备通讯接口类型(1—RS-232C,2—USB)
返 回 值:生成*.bmp文件和以下返回信息
值 意义
1 相片解码解码正确
0 调用sdtapi.dll错误
-1 相片解码错误
-2 wlt文件后缀错误
-3 wlt文件打开错误
-4 wlt文件格式错误
-5 软件未授权
-6 设备连接错误
五、注意事项
1、 wlt文件的后缀要固定为”.wlt”,如:xp.wlt,相片解码成xp.bmp;
2、 本函数要与sdtapi.dll关联使用,并确认通讯端口处于关闭状态;
相关文章推荐
- php读取本地文件常用函数(fopen与file_get_contents)
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- PHP文件操作,多行句子的读取,file()函数,file_get_contents()函数,file_put_contents()函数,is_file,统计网站pv (访问量),文件的复制 copy
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- fread与file_get_contents读取函数文件
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- 怎么读取二代身份证UUID----在STM32+CLRC663平台试验成功
- 一些读取字符函数小结(getchar getch getche)
- 在使用simplexml_load_file()函数读取xml文件时遇到<![CDATA[]]>,怎么让其进行解析
- php读取本地文件常用函数(fopen与file_get_contents)
- 文件磁盘相关函数[12]-读取文件属性 FileGetAttr
- file_get_contents( ) 函数,读取".php"结尾文件
- fread()、fgets()、fgetc()、file_get_contents() 与 file() 函数用于从文件中读取内容。
- PHP读取文件函数fread,fgets,fgetc,file_get_contents和file函数的使用总结
- php 在linux 用fopen() 函数打开,file_get_contents(),fread()函数 读取 另外一台服务器映射过来的文件 总是返回false,null的情况。
- GetCurrentDirectory()和GetModuleFileName()函数的区别
- PHP PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
- file_get_contents读取远程xml文档
- 读取软件的版本信息 GetFileVersionInfo