1. Binary conversion to Picture
New0= Image.fromstream (ms); Ms. Close ();
2.c# in byte[] and string conversion Code
1):
var New System.Text.UnicodeEncoding (); byte [] Inputbytes = converter. GetBytes (""); string 0, inputbytes.length);
2):
String inputstring = System.Convert.ToBase64String (inputbytes);
byte[] inputbytes = System.Convert.FromBase64String (inputstring);
FileStream FileStream = new FileStream (FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
3. Conversion between C # Stream and byte[]
Public byte[] Streamtobytes (Stream stream) {byte[] bytes =New byte[Stream. Length]; Stream. Read (Bytes,0, Bytes. Length); //sets the position of the current stream as the start of the streamStream. Seek (0, Seekorigin.begin); returnbytes;}//turn byte[] into a Stream PublicStream Bytestostream (byte[] bytes) {Stream Stream=NewMemoryStream (bytes); returnstream;}
Conversion between 4.Stream and files
Public voidStreamtofile (Stream stream,stringfileName) { //convert Stream to byte[] byte[] bytes =New byte[Stream. Length]; Stream. Read (Bytes,0, Bytes. Length); //sets the position of the current stream as the start of the streamStream. Seek (0, Seekorigin.begin); //write byte[] to fileFileStream fs =NewFileStream (FileName, FileMode.Create); BinaryWriter BW=NewBinaryWriter (FS); Bw. Write (bytes); Bw. Close (); Fs. Close ();}5. Reading Stream from a file
PublicStream Filetostream (stringfileName) { //Open FileFileStream FileStream =NewFileStream (FileName, FileMode.Open, FileAccess.Read, FileShare.Read); //read the file byte[] byte[] bytes =New byte[Filestream.length]; FileStream.Read (Bytes,0, Bytes. Length); Filestream.close (); //convert byte[] to StreamStream stream =NewMemoryStream (bytes); returnstream;}6.Bitmap conversion to byte[]
New Bitmap (); byte NULL new= Ms. GetBuffer ();
Conversion between Stream and byte[]