public string ImageToBase64String(Image imageData, ImageFormat format)
{
string base64;
MemoryStream memory = new MemoryStream();
imageData.Save(memory, format);
base64 = System.Convert.ToBase64String(memory.ToArray());
memory.Close();
memory = null;
return base64;
}
或
System.IO.MemoryStream m = new System.IO.MemoryStream();
System.Drawing.Bitmap bp = new System.Drawing.Bitmap(@“c:/a.GIF”);
bp.Save(m, System.Drawing.Imaging.ImageFormat.Gif);
byte[]b= m.GetBuffer();
string base64string=Convert.ToBase64String(b);
byte[] bt = Convert.FromBase64String(base64string);
System.IO.MemoryStream stream = new System.IO.MemoryStream(bt);
Bitmap bitmap = new Bitmap(stream);
pictureBox1.Image = bitmap;
string s= "";
byte[] b = Convert.FromBase64String(s);
Response.ClearContent();
Response.AddHeader("Content-Type","image/gif");
Response.BinaryWrite(b);
Response.End();
byte[] b = (byte[])(二进制数据);
pic.Image = Image.FromStream(new MemoryStream(b));
picData = b;