Convert image to binary?

前端 未结 8 2226
南旧
南旧 2021-02-08 04:07

I have an image (in .png format), and I want this picture to convert to binary.

How can this be done using C#?

8条回答
  •  猫巷女王i
    2021-02-08 04:31

    System.Drawing.Image image = System.Drawing.Image.FromFile("filename");
    byte[] buffer;
    MemoryStream stream = new MemoryStream();
    image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
    
    buffer = stream.ToArray(); // converted to byte array
    stream = new MemoryStream();
    stream.Read(buffer, 0, buffer.Length);
    stream.Seek(0, SeekOrigin.Begin);
    System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
    

提交回复
热议问题