473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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

Nov 15 '05 #1
3 4786
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
try the static

byte[] b;
BitConveter.ToUInt16(b, 0);
<Ol**********@skyscan.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
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

Nov 15 '05 #3
> >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. :-)
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Daniel | last post by:
in C# fastest way to convert a string into a MemoryStream
1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
6
by: Hardy Wang | last post by:
Hi all: The Stream object from WebRequest.GetResponseStream() is non-seekable. How can I convert this stream to a byte array? For ordinary Stream (seekable), I can use...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
3
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As...
8
by: Prakash | last post by:
Hi Friends, Using Remoting concept, i have send WCHAR values from VC++.net applicaiton to C# applicaiton. In my C# application it is treated as unsigned shot. I need to convert it back to string...
8
by: piggy | last post by:
I am trying to convert an image to an byte array (tobytes() method) and from byte array back to an image (frombytes() method). The problem i have here is say the image size is 285 bytes but the...
2
by: =?Utf-8?B?U3VzaGlTZWFu?= | last post by:
Hello, I have a question. byte network = new byte; And I know what in this byte array in position from 4 to 8 it is long value, and from 10 to 12 is it ushort type. I need do something like...
1
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, Assuming I have a class/struct with only following types float, int, string what is the most efficient way to pack it to a single byte array before I send it out. I tried to use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.