我是做用JNative 读取身份证读卡器信息的功能,现在其他的文字信息都能得到,但照片信息不知道如何读。。代码如下: // 读照片
JNative n8 = new JNative("Termb", "CVR_ReadBaseMsg");
Pointer pointer11 = new Pointer(MemoryBlockFactory.createMemoryBlock(1000));
Pointer pointer12 = new Pointer(MemoryBlockFactory.createMemoryBlock(256));
Pointer pointer13 = new Pointer(MemoryBlockFactory.createMemoryBlock(1024 * 100));
Pointer pointer14 = new Pointer(MemoryBlockFactory.createMemoryBlock(1024));
int i = 0;
n8.setParameter(i++, pointer11);
n8.setParameter(i++, pointer12);
n8.setParameter(i++, pointer13);
n8.setParameter(i++, pointer14);

n8.setParameter(i++, 4);
n8.setRetVal(Type.INT);
n8.invoke();
System.out.println("返回:"+n8.getRetVal());//这里返回1,表示成功调用 byte[] images = pointer13.getMemory();//问题就在这,这里得到的数组值是全是0,如何能得到保存在内存里的照片信息呢?

byte[] bb = new byte[1024*40];
for (int j = 0; j < images.length; j++) {
if (images[j]!=0) {
bb[j] =images[j];
}
}

String newFileName = "D:/work/test/images/1.bmp";
InputStream in = new ByteArrayInputStream(bb, 0, bb.length);
FileOutputStream fos = new FileOutputStream(newFileName);
int len;
byte[] buf = new byte[1024];
while ((len = in.read(buf, 0, 1024)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
这个是开发包里对CVR_ReadBaseMsg的说明:读文字、照片信息到自定义内存缓冲
原  型:int CVR_ReadBaseMsg (unsigned char *pucCHMsg, unsigned int *puiCHMsgLen,  unsigned char *pucPHMsg, unsigned int *puiPHMsgLen,int nMode) 
参 数 说 明 备 注
pucCHMsg 身份文字信息内存缓冲指针 方向:Out
puiCHMsgLen 身份文字信息长度 默认 256 Byte
pucPHMsg 身份照片信息内存缓冲指针 方向:Out
puiPHMsgLen 身份照片信息长度 默认 1024 Byte
nMode 传入参数 1 文字编码为默认UCS-2格式,照片未解压成bmp文件
传入参数 2 文字编码已转换成GBK国标码格式,照片未解压成bmp文件
传入参数 3 文字编码为默认UCS-2格式,照片已解压成zp.bmp文件
传入参数 4 文字编码已转换成GBK国标码格式,照片已解压成zp.bmp文件返 回 值:
返回值 意义
1 正确
0 错误
做过的程序朋友帮帮忙,谢谢!!!!!

解决方案 »

  1.   

    如果把 n8.setParameter(i++, 4); 参数4换成2的话,数组images 的 0~1023 里面是有值的,但是得到的bmp图片不能显示,好像是加密过的
      

  2.   

    可能编码格式不正确吧,用C++或已有的demo调用函数,看看得到的数组内容是什么,和你的相比有什么区别?还有就是每个opinter后面要加一个p.zeroMemory(),试试能不能解决。
    还有一个疑问就是:
    Pointer pointer13 = new Pointer(MemoryBlockFactory.createMemoryBlock(1024 * 100)); 
    byte[] images = pointer13.getMemory();
    byte[] bb = new byte[1024*40]; 
    byte[] buf = new byte[1024];
    如果按照pointer13来分配内存的话,应该都是1024*100,为什么后来越来越少?不知道LZ怎么考虑的