Category Archives: images into entity framework

Save and retrieve images using Entity Framework C#

If you have an image field in the table, you have to save the image as an array of bytes:

using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
public byte[] ImageToByteArray(Image imageIn)
 var ms = new MemoryStream();
 imageIn.Save(ms, ImageFormat.Png);
 return ms.ToArray();
public Image ByteArrayToImage(byte[] byteArrayIn)
 var ms = new MemoryStream(byteArrayIn);
 var returnImage = Image.FromStream(ms);
 return returnImage;