Here's how I do it:
Convert Image to byte[] array:
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] bytes = ms.ToArray();
Convert byte[] array to Image:
MemoryStream ms = new MemoryStream(bytes);
Image imageOut = Image.FromStream(ms);
Don't go via strings unless you absolutely have to - and then use Base64 instead of "regular" strings - strings are always Unicode, and some of the values in your image can be interpreted wrongly by regular strings, leading to a byte array that isn't identical to the original after conversion.
[edit]
Quote:
How can I achieve sending image file name and image both in the same byte[]?
The sensible way would be to create a container class which holds a string and a byte array properties.
Then use JSON to build an easily transferable string, and deserialize it at the end.
If you use Newtonsoft.Json, it's trivial:
Image image = Bitmap.FromFile(@"D:\Test Data\MyPic.jpg");
pictureBox1.Image = image;
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ImageWithName iwm1 = new ImageWithName() { Name = "Hello.jpg", ImageData = ms.ToArray() };
string jsonBody = JsonConvert.SerializeObject(iwm1);
...
ImageWithName iwm2 = JsonConvert.DeserializeObject<ImageWithName>(jsonBody);
ms = new MemoryStream(iwm2.ImageData);
image = Bitmap.FromStream(ms);
pictureBox2.Image = image;
[/edit]