How to convert image format to byte array

Image to byte array C#

public ActionResult Index()
{
    var byterResult = GetBytesFromImage(Server.MapPath(@"~\image\1.png"));

    return View();
}


private byte[] GetBytesFromImage(String imageFile)
{
    MemoryStream ms = new MemoryStream();
    Image img = Image.FromFile(imageFile);
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

    return ms.ToArray();
}

How to convert image format to byte array How to convert image format to byte array Reviewed by Bhaumik Patel on 10:17 PM Rating: 5