A.J A.J - 1 year ago 168
C# Question

Convert image path to base64 string

How do you convert an image to a base64 string in C#?

For example, I have the path to the image

and would like

Answer Source

Try this

  using (Image image = Image.FromFile(Path))
        using (MemoryStream m = new MemoryStream())
            image.Save(m, image.RawFormat);
            byte[] imageBytes = m.ToArray();

            // Convert byte[] to Base64 String
            string base64String = Convert.ToBase64String(imageBytes);
            return base64String;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download