Base64

Image To Base64 String

void Main()
{
    var path = @"path_to_image\1.png";
    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);
            Console.WriteLine("data:image/png;base64,{0}",base64String);
        }                  
    }
}

Latest Updates

© 0 - 2025 - Mike Brind.
All rights reserved.
Contact me at Mike dot Brind at Outlook.com