2012-08-10

Convert image to a byte array in ASP.Net

Following example shows how to take the byte representation of an image.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            string strPhoto = (@"C:\\Webcam.jpg");
            FileStream fs = new FileStream(strPhoto, FileMode.Open, FileAccess.Read);

            Byte[] imgByte = new byte[fs.Length];

            fs.Read(imgByte, 0, System.Convert.ToInt32(fs.Length));
        }

    }
}

No comments: