0

I have a long pointer that has been passed from c++ to java that refers to an image data, now i want to retrieve the array from this pointer in java ,how can i do this what i have is long ptr in java

i tried this code but i dont know how to make ptr refer to _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 Answer 1

1

According to jna.java.net Documentation read function has the following parameters:

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. As you can see first parameter is byte offset from the pointer data is copied. in your case 0.
  2. The second parameter is byte array the data is copied. In your case the pointer pointing to the actual image data, or _pointer.
  3. The third parameter is array index in destination which would be 0 again.
  4. and the fourth parameter number of bytes to copy which seems to be 2*512*512.

Hope this helps you.

Sign up to request clarification or add additional context in comments.

2 Comments

it says that there's not a suitable method that takes int,long,int,int..that happened when i placed _pointer in the second argument :)
I really don't know anything about this API. I tried to figure it from the documentation. Sry if I wasted your time :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.