// This code example demontrates how to convert a PNG image to Base64 string in C#. // Load an input JPG image var bytes = File.ReadAllBytes(@"C:\Files\Sample.png"); // Initialize an SVGDocument object var document = new SVGDocument(); // Create an image element var img = (SVGImageElement)document.CreateElementNS("http://www.w3.org/2000/svg", "image"); // Convert image to Base64 img.Href.BaseVal = "data:image/png;charset=utf-8;base64," + Convert.ToBase64String(bytes); // Add the image element into the SVG document document.RootElement.AppendChild(img); // Save the SVG document document.Save(@"C:\Files\image-base64.svg");