ASP.NET - image to binary - Asked By rahul patil on 04-May-12 09:03 AM

Earn up to 10 extra points for answering this tough question.
i want to convert the logo image direct to binary remember that the image i not in file upload , how to do this please reply me thanks
Jitendra Faye replied to rahul patil on 04-May-12 10:36 AM
If you don't want to use fileUpload control then go like this-

FileStream fs = new FileStream(Server.MapPath("../Images/img1.jpg"),
FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] imagedata = br.ReadBytes(Convert.ToInt32 (  br.BaseStream.Length));

TRy this and let me know.
[)ia6l0 iii replied to rahul patil on 04-May-12 09:33 PM
You should rephrase your questions as "how to convert binary image to byte array".

The System.IO.File namespace provides the RealAllBytes method that reads the contents of the image and returns you a byte array. 

byte[] imgData = System.IO.File.ReadAllBytes(path of the file);

This is the shortest way I know. 

Hope this helps.