In this post, we will learn to convert and retrieve an image from base64. First, we will convert the image into base64 from a URL and second, convert the image from base64 using memory stream. The last step is to display the image in the image box using MemoryStream.
Here, we will use the byte array of the images for converting and retrieving the images. Follow the code written below. For this project, we are using a web application for displaying the image from base64.
First, we need to add the below namespace for converting the image.
- using System.Web;
- using System.IO;
- using System.Drawing;
- string DefaultImagePath = HttpContext.Current.Server.MapPath("~/NoImage.jpg");
- byte[] imageArray = System.IO.File.ReadAllBytes(DefaultImagePath);
- string base64ImageRepresentation = Convert.ToBase64String(imageArray);
- byte[] bytes = Convert.FromBase64String(base64ImageRepresentation);
- using (MemoryStream ms = new MemoryStream(bytes))
- {
- pic.Image = Image.FromStream(ms);
- }


Hadshana KamalanathanTOP 100Posted Sep 7, 2018, 6:42 AM EDT
Thanks for sharing....
Hardik DeshaniPosted Sep 6, 2018, 11:23 PM EDT
Thnx you Amol Kumbhkarna
Amol KumbhkarnaPosted Sep 6, 2018, 9:21 PM EDT
Great article hardik ....!!! Keep It Up...!!!