详谈C# 图片与byte[]之间以及byte[]与string之间的转换
时间:2021-08-18 08:16:45|栏目:.NET代码|点击: 次
实例如下:
//主要通过Stream作为中间桥梁
public static Image ByteArrayToImage(byte[] iamgebytes) {
MemoryStream ms = new MemoryStream(iamgebytes);
Image image = Image.FromStream(ms);
return image;
}
public static byte[] ImageToByteArray(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 string StringToByteArray(string image) {
return Convert.FromBase64String(image);
}
栏 目:.NET代码
本文标题:详谈C# 图片与byte[]之间以及byte[]与string之间的转换
本文地址:http://www.codeinn.net/misctech/167920.html






