Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created May 6, 2024 06:39
Show Gist options
  • Save aspose-com-gists/b8160bf755bebaa291f16c03e8435786 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b8160bf755bebaa291f16c03e8435786 to your computer and use it in GitHub Desktop.
Convert JPG to Base64
// This code example demontrates how to convert a JPG image to a Base64 string in C#.
using Aspose.Svg;
// Load an input JPG image
var bytes = File.ReadAllBytes(@"Sample_JPG.jpg");
// 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/jpg;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(@"image-base64.svg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment