Created
April 30, 2012 10:54
-
-
Save AndrewBarfield/2557343 to your computer and use it in GitHub Desktop.
C#: Converting an image to Base64 / Data URI scheme
This file contains hidden or 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
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 ) + "\"/>"; | |
} | |
} |
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
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?