代码如下 | 复制代码 |
//主要通过Stream作为中间桥梁 publicstaticImage ByteArrayToImage(byte[] iamgebytes) { MemoryStream ms =newMemoryStream(iamgebytes); Image image = Image.FromStream(ms); returnimage; }
publicstaticbyte[] ImageToByteArray(Image image) { MemoryStream ms =newMemoryStream(); image.Save(ms, image.RawFormat); returnms.ToArray(); }
publicstaticstringByteArrayToString(byte[] bytes) { returnConvert.ToBase64String(bytes); }
publicstaticstringStringToByteArray(stringimage) { returnConvert.FromBase64String(image); } |