shko
shko

Reputation: 41

How to cast 'System.IntPtr' to 'float[]'?

How can I get a float[] for this IntPtr so I can operate on it? Or please let me know any method can be operated. (I've tried using Array, Marshaling but all doesn't operate.) Please see the following.

Any help would be appreciate!

IntPtr pt = IntPtr.Zero;
Camera.Memory.ToIntPtr(s32MemID, out pt);

MIL.MbufPut(MilImage, pt); 

> C:\Ctest\idsCS\idsCS\Form1.cs(100,35): error CS1503: Argument '2': cannot convert from 'System.IntPtr' to 'float[]'

Syntax for those methods

uEye.Memory.ToIntPtr(out System.IntPtr ptr)
**uEye.Memory.ToIntPtr**(int s32MemId, out System.IntPtr ptr)

Description
Returns a pointer to the image memory of the active/given image memory ID.

Parameter

s32MemId(Image memory ID)

ptr(Pointer to the image memory)
  void **MbufPut**(
  MIL_ID DestBufId,  //in  
const void *UserArrayPtr  //in  
)

Upvotes: 3

Views: 6276

Answers (2)

Baranovskiy Dmitry
Baranovskiy Dmitry

Reputation: 463

Nowadays, I would use Span

IntPtr ptr = ... ;
Span<T> sp = new Span<T>((T*)ptr, ...);

But this still has some limitations. Take into account that Span is a read-only struct and can be allocated only on the stack.

Upvotes: 1

Jcl
Jcl

Reputation: 28272

Use Marshal.Copy (this overload: http://msdn.microsoft.com/en-us/library/a53bd6cz(v=vs.80).aspx )

Upvotes: 4

Related Questions