I want to convert an ushort * to a byte[] array needed for the Memorystream

G

Guest

I want to convert an ushort * to a byte[] array needed for the Memorystream

ushort *pshort=FileImageBuffer16.GetPtr(0,iY);
Stream.Write((byte[]) pshort,0,iWidth*2);

The big problem is that (ushort*) typecasting to (byte[] ) gives me
headaches.
Any idea how to do this?

Thanks
 
M

Mattias Sjögren

The big problem is that (ushort*) typecasting to (byte[] ) gives me
headaches.
Any idea how to do this?

Copy it into a local byte[] first

byte[] buffer = new byte[iWidth*2];
Marshal.Copy( (IntPtr)pshort, buffer, 0, buffer.Length );



Mattias
 
G

Guest

The big problem is that (ushort*) typecasting to (byte[] ) gives me
headaches.
Any idea how to do this?

Copy it into a local byte[] first

byte[] buffer = new byte[iWidth*2];
Marshal.Copy( (IntPtr)pshort, buffer, 0, buffer.Length );

This seems to work great. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top