圖片和二進位制轉化
阿新 • • 發佈:2019-02-10
/// <summary>
/// 二進位制轉圖片
/// </summary>
/// <param name="streamByte"></param>
/// <returns></returns>
public static Image TransformImage(string imageStr)
{
byte[] bytes = Convert.FromBase64String(imageStr);
MemoryStream ms = new MemoryStream(bytes);
BinaryFormatter bf = new BinaryFormatter();
Image img = (Image)bf.Deserialize(ms);
return img;
}
/// <summary>
/// 圖片轉二進位制
/// </summary>
/// <param name="imagepath"></param>
/// <returns></returns>
public static string TransformByte(Image img)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, img);
byte[] bytes = ms.GetBuffer();
string imageStr = Convert.ToBase64String(bytes);
return imageStr;
}
/// 二進位制轉圖片
/// </summary>
/// <param name="streamByte"></param>
/// <returns></returns>
public static Image TransformImage(string imageStr)
{
byte[] bytes = Convert.FromBase64String(imageStr);
MemoryStream ms = new MemoryStream(bytes);
BinaryFormatter bf = new BinaryFormatter();
Image img = (Image)bf.Deserialize(ms);
return img;
}
/// <summary>
/// 圖片轉二進位制
/// </summary>
/// <param name="imagepath"></param>
/// <returns></returns>
public static string TransformByte(Image img)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, img);
byte[] bytes = ms.GetBuffer();
string imageStr = Convert.ToBase64String(bytes);
return imageStr;
}