How do I convert pictures and sounds to byte[] and transfer them through webservice?
How to transfer the WebService to byte[] and convert it into the file we want?
(i) Conversion of documents to byte[]
Method One: Use MemoryStream (MemoryStream data from in-memory buffers)
System.IO.MemoryStream m = new System.IO.MemoryStream ();
System.Drawing.Bitmap bp = new System.Drawing.Bitmap (pname);
Bp. Save (M, System.Drawing.Imaging.ImageFormat.Jpeg);//saves this image to the specified stream in the specified format.
Byte[] B = m.getbuffer ();//read from memory buffer
Method Two: Use FileStream (FileStream object's data from file)
FileStream stream = new FileInfo (path). OpenRead ();
byte[] buffer = new Byte[stream. Length];
Reads a block of bytes from the stream and writes the data to the given buffer
Stream. Read (buffer, 0, Convert.ToInt32 (stream). Length));
(ii) conversion of byte[] into a document
Webreference.myservice obj = new Webreference.myservice ();
Byte[] B = obj.downwav ("1001"),//1001 the PID of a record, returns the byte[of the picture in this record]
MemoryStream m = new MemoryStream (b);
String file =string. Format (@ "{0}\e.wav",
Path.getdirectoryname (assembly.getexecutingassembly (). GetName (). CodeBase));
Put the downloaded files in the current directory, save as E.wav, of course, if it is a picture, can be saved as a.jpg
FileStream fs = new FileStream (file, FileMode.OpenOrCreate);
M.writeto (FS);
M.close ();
Fs. Close ();
m = null;
FS = null; File and byte[in C #] interchange issues
From:http://www.cnblogs.com/qiuweiguo/archive/2011/08/05/2128690.html
File and byte[in C #] interchange issues