Search code examples
c#.netwpfsilverlight

How to Convert system.windows.controls.image to byte[]


I need to convert System.Windows.Controls.Image to byte[].

How to do it ?


Solution

  • Assuming that you answer my query above that you are actually trying to convert an image into a byte array rather than an image control into a byte array here is the code to do so;

    public byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
     MemoryStream ms = new MemoryStream();
     imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
     return  ms.ToArray();
    }