Last active
August 29, 2015 14:22
-
-
Save danleyb2/179372b592ea89e27cdf to your computer and use it in GitHub Desktop.
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
public Image Base64ToImage(string base64String) | |
{ | |
// Convert Base64 String to byte[] | |
byte[] imageBytes = Convert.FromBase64String(base64String); | |
MemoryStream ms = new MemoryStream(imageBytes, 0, | |
imageBytes.Length); | |
// Convert byte[] to Image | |
ms.Write(imageBytes, 0, imageBytes.Length); | |
Image image = Image.FromStream(ms, true); | |
return image; | |
} |
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
public string ImageToBase64(Image image, | |
System.Drawing.Imaging.ImageFormat format) | |
{ | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
// Convert Image to byte[] | |
image.Save(ms, format); | |
byte[] imageBytes = ms.ToArray(); | |
// Convert byte[] to Base64 String | |
string base64String = Convert.ToBase64String(imageBytes); | |
return base64String; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment