1. Convert the string into a byte array
String imgData = "....,...,....,....";
String [] imgArr = imgData. Split (new char [] {','});
Byte [] bty = Array. ConvertAll <string, byte> (imgArr, delegate (string s) {return byte. Parse (s );});
2. Convert the byte array into a string
There are two main methods:
String. Join (): Concatenates the specified separator String between each element of the specified String array to generate a single concatenation String.
Array. ConvertAll (): converts one type of Array to another type of Array.
For example, the ArraySource (byte) elements in the target array are separated by commas (,) and the output string is used.
String result = String. Join (",", Array. ConvertAll (ArraySource, (Converter <byte, string>) Convert. ToString ));
----------------------------------------------------------------------------
// Image --> Byte [] --> String
Byte [] bytes = File. ReadAllBytes (@ "d: \ a.gif ");
MemoryStream MS = new MemoryStream (bty );
String imgStr = Convert. ToBase64String (ms. ToArray ());
// String --> Byte [] --> Image
Byte [] imgBytes = Convert. FromBase64String (imgStr );
Response. BinaryWrite (imgBytes. ToArray (); // write a binary string to the HTTP output stream