2013-01-03 78 views
0

我有一个长指针,已经从C++传递到指向图像数据的java,现在我想从java中的这个pointer检索数组,如何我能做到这一点 我有什么是Java中长PTR如何将传递的C++长指针转换为java指针或数组

我想这代码,但我不知道如何使PTR指_Pointer

long _pointer=Image.GetCptr(); 
com.sun.jna.Pointer ptr = new com.sun.jna.Memory(2 * 512 * 512); 
short testarr[] = new short [512 * 512]; 
ptr.read(_pointer, testarr, 0, testarr.length); 

回答

1

根据jna.java.net Documentation读功能具有下列参数:

public void read(long offset, 
      byte[] buf, 
      int index, 
      int length) 

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array. 

Parameters: 
    offset - byte offset from pointer into which data is copied 
    buf - byte array into which data is copied 
    index - array index from which to start copying 
    length - number of elements from native pointer that must be copied 
  1. 正如您所看到的第一个参数是byte offset from the pointer data is copied。在你的情况下0.
  2. 第二个参数是byte array the data is copied。在你的情况下,指针指向实际的图像数据,或_指针。
  3. 第三个参数是array index in destination这将再次为0。
  4. 和第四个参数要复制的字节数似乎是2 * 512 * 512。

希望这可以帮助你。

+0

Thanks Fardad我会试试这个 –

+0

它说没有一个合适的方法需要int,long,int,int ..发生在我把_pointer放在第二个参数中时:) –

+1

我真的不知道什么关于这个API。我试图从文档中找出它。 Sry,如果我浪费了你的时间:) – user59169

相关问题