Learn how to Convert JPG to Base64 Online
Created
May 6, 2024 06:39
-
-
Save aspose-com-gists/b8160bf755bebaa291f16c03e8435786 to your computer and use it in GitHub Desktop.
Convert JPG to Base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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