The previous article explains how to convert the obtained data stream into a Bitmap image)
In turn, how can we achieve this?
This principle is relatively simple. It also uses memory serialization to directly serialize the image to the memory, and deserializes the stream in the memory into a byte array.
In combination with the previous article, we can easily convert data streams and images.
The Code is as follows:
Code
Using System;
Using System. IO;
Public byte [] ToByte (Image imageData)
{
MemoryStream MS = new MemoryStream ();
Image. Save (MS, System.Drawing.Imaging.ImageFormat.bmp); // serialize image data to memory
Byte [] imgByte = new byte [Ms. Length];
Ms. Position = 0;
Ms. Read (imgByte, 0, Convert. ToInt32 (Ms. Length); // reverse sequence, stored in the byte array
Ms. Close ();
Return imgByte; // here we get the byte array of the image.
}