欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

详谈C# 图片与byte[]之间以及byte[]与string之间的转换

程序员文章站 2023-11-09 17:59:58
实例如下: //主要通过stream作为中间桥梁 public static image bytearraytoimage(byte[] iamgebytes)...

实例如下:

//主要通过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之间的转换就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。