Convert Image to base64 string and base64 string to byte array in ASP.Net using C# and VB.Net

paulrajmca
 
on Aug 17, 2021 03:10 AM
2269 Views

Hi developers,

In my project i need to convert an base64 string to image and again convert the image to byte array in web service c#

1. Convert base64 to original image

2. Convert original image to byte array

Kindly help me to done this task.

 

Regards,

Puul.S

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Andrea
 
on Aug 17, 2021 03:11 AM

Hi @paulrajmca,
Please try the following

Convert base64 string to byte array and save as image file in C# .Net

It might help you.

Cheers Andrea.

paulrajmca
 
on Aug 17, 2021 07:43 AM
on Aug 17, 2021 07:43 AM

Thanking you for your quick response , i have done this as the following query.

byte[] imageBytes = Convert.FromBase64String(KYCImageRequest.IDProofImageData);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
System.Drawing.Image idProofImage = System.Drawing.Image.FromStream(ms, true);
byte[] idProofBytes = ImageToByte(idProofImage);

Regards,

Paul.S