How to convert an image to byte array in c#


private void Form1_Load(object sender, EventArgs e)
// create an Image object from File
Image image = Image.FromFile(@”D:testbridge.jpg”);
// create a MemoryStream
var ms = new MemoryStream(); // this is where we are going to deposit the bytes
// save bytes to ms
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
// to get the bytes we type
var bytes = ms.ToArray();
// we can now save the byte array to a db, file, or transport (stream) it.


Xem Thêm Bài Viết Khác:


  1. In the age, where the microphones are so common that you have to cover them up not to get spied on, some people still can't find one. Well, at least the music was nice. 🙂

  2. Hello sir i want to know how to convert an image into byte Array actually i want to compare two images in WPF before comparing we need to convert those images into byte array please reply me as soon as possible and you can reply me at if it is possible you can provide me a source code in which we can convert images instances and then compare it Thanks

  3. I am trying to write the bytes in a csv but when I read the whole array, it only prints 37.132 numbers from a 600 x 400 pixels image. What's wrong.

  4. sir this is my image URL ( I want to know the Size of image in bytes using How to do this?? Thanks


Please enter your comment!
Please enter your name here