Image into byte[]

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,to all

I would like to know how could i put the content of image file into byte[]

cause im trying to copy the image as a file and the image its copied at the
path that i want, but i cant open cause i dont copy it as a byte[].

Any help will be grateful.
Thnx.
 
Hi Josema,

If I understand you correctly, this is what you want:

FileStream fs = File.Open("filename", FileMode.Open);

byte[] data = new byte[fs.Length];

fs.Read(data, 0, data.Length);
fs.Close();

If you later need to put that byte[] into an Image object you can load the data into a MemoryStream and create an image using Image.FromStream.

Then again, a simple File.Copy() may be what you want.
 
Back
Top