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 KamalanathanPosted Sep 7, 2018, 10:42 AM
Thanks for sharing....
Hardik DeshaniPosted Sep 7, 2018, 3:23 AM
Thnx you Amol Kumbhkarna
Amol KumbhkarnaPosted Sep 7, 2018, 1:21 AM
Great article hardik ....!!! Keep It Up...!!!