2013-01-03 76 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

相關問題