Convert image to binary?

前端 未结 8 2199
南旧
南旧 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条回答
  • 2021-02-08 04:56

    First, convert the image into a byte array using ImageConverter class. Then specify the mime type of your png image, and voila!

    Here's an example:

    TypeConverter tc = TypeDescriptor.GetConverter(typeof(Byte[]));
    Response.ContentType = "image/png";
    Response.BinaryWrite((Byte[])tc.ConvertTo(img,tc));
    
    0 讨论(0)
  • 2021-02-08 04:57

    Try this:

    Byte[] result 
        = (Byte[])new ImageConverter().ConvertTo(yourImage, typeof(Byte[]));
    
    0 讨论(0)
提交回复
热议问题