//主要通过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);
}C# 图片与byte[]之间以及byte[]与string之间的转换
最新推荐文章于 2023-06-15 18:49:57 发布
本文介绍了如何使用C#进行图片与字节流之间的相互转换,包括将图片转换为字节数组、从字节数组还原图片以及字节数组与Base64字符串之间的转换。

2429

被折叠的 条评论
为什么被折叠?



