using System; using System.Drawing; using System.IO; namespace EC.Utils.ImageHelpers { public partial class ImageHelper { public static byte[] ImageToByteArray(System.Drawing.Image imageIn) { try { if (imageIn == null) { return null; } MemoryStream ms = new MemoryStream(); imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return ms.ToArray(); } catch (Exception ex) { return null; } } public static Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; } } }