Convert Image to Base64 String in C#

By: Syed Emailed: 1612 times Printed: 2078 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

This article will help you to learn how we can convert an image into a base64 string and base64 string back to image.
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;
  }
}

Csharp Home | All Csharp Tutorials | Latest Csharp Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Syed
Convert Base64 String to Image in C#
Convert Image to Base64 String in C#

More Tutorials in Csharp
Major features of C#
Categories of datatypes in C#
Boxing and unboxing in C#
Preprocessor directives in C#
Comments in C#
Hello World sample program in C#
SOAP serialization in C#
What is C#?
Design Goals of C#
Why it was named C#?
History of C#?
Which version of C# to use?
Convert Image to Base64 String in C#
Convert Base64 String to Image in C#

More Latest News
Most Viewed Articles (in Csharp )
Boxing and unboxing in C#
Convert Base64 String to Image in C#
History of C#?
Convert Image to Base64 String in C#
SOAP serialization in C#
What is C#?
Why it was named C#?
Which version of C# to use?
Categories of datatypes in C#
Comments in C#
Hello World sample program in C#
Design Goals of C#
Major features of C#
Preprocessor directives in C#
Most Emailed Articles (in Csharp)
History of C#?
Convert Image to Base64 String in C#
What is C#?
Why it was named C#?
Convert Base64 String to Image in C#
SOAP serialization in C#
Design Goals of C#
Which version of C# to use?
Major features of C#
Comments in C#
Preprocessor directives in C#
Hello World sample program in C#
Boxing and unboxing in C#
Categories of datatypes in C#