using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
public class ImageConvert
{
//主要通过Stream作为中间桥梁
public static Image ByteArrayToImage(byte[] iamgebytes)
{
MemoryStream ms = new MemoryStream(iamgebytes);
System.Drawing.Image image = Image.FromStream(ms);
return image;
}
public static byte[] ImageToByteArray(System.Drawing.Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, image.RawFormat);
return ms.ToArray();
}
public static string ByteArrayToString(byte[] bytes)
{
return Convert.ToBase64String(bytes);
}
public static byte[] StringToByteArray(string str)
{
return Convert.FromBase64String(str);
}
}
本文转自:http://hi.baidu.com/enkyo/blog/item/0c1cbe8b8e734b7c9e2fb4a2.html