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

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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. :-)
 
Back
Top