Skip to content

Instantly share code, notes, and snippets.

@AndrewBarfield
Created April 30, 2012 10:54
Show Gist options
  • Save AndrewBarfield/2557343 to your computer and use it in GitHub Desktop.
Save AndrewBarfield/2557343 to your computer and use it in GitHub Desktop.
C#: Converting an image to Base64 / Data URI scheme
private void B64Encode()
{
Image a = new Bitmap( @".../path/to/image.png" );
using ( MemoryStream ms = new MemoryStream() )
{
// Convert Image to byte[]
a.Save( ms, a.RawFormat );
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
this.richTextBox1.Text = "<img src=\"data:image/png;base64," + Convert.ToBase64String( imageBytes ) + "\"/>";
}
}
Copy link

ghost commented May 2, 2018

in some of browsers Data URL have limitations
and converting to base64 gets long time for large files
how can i convert bytes to image without Data URL?

@Seanmclem
Copy link

in some of browsers Data URL have limitations
and converting to base64 gets long time for large files
how can i convert bytes to image without Data URL?

What do you have instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment