How to convert an image to byte array in c#

11
1



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.
}

Nguồn:https://wijstaanvooronzegrondrechten.org/

Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe

11 COMMENTS

  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 Shahrukh38516@yahoo.com 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 (https://media.licdn.com/mpr/mprx/0_QCAaj3fWjKyLo1-UnakGa3yWtzyjolBjoDnGrk0Ij0d-ocPrnwLma3yLjJfLIc6roSXltGDe8yfxQOGx9HKNGXfq8yfpQOlV9HKJCIyo8ydxQPX3oeLmPSf_AzuRntmQIZtl) I want to know the Size of image in bytes using Asp.net. How to do this?? Thanks

LEAVE A REPLY

Please enter your comment!
Please enter your name here