Tutorials Archive Save and Share your Tutorials

17Sep/090

Convert Image to Base64 String and Base64 String to Image

This article will help you to learn how we can convert an image into a base64 string and base64 string back to image.

Image to Base64 String

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;
  }
}


Base64 String to Image

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;
}
VN:F [1.6.4_902]
Rating: 0.0/5 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)

No related posts.

Tagged as: Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Subscribe via Email

Follow me on Twitter

Categories

Archives

Calendar

September 2009
M T W T F S S
    Feb »
 123456
78910111213
14151617181920
21222324252627
282930  

Recent Posts

Recent Comments

Link Exchange

Meta

Stats

Web Directory

Internet photoshop tutorials, free photoshop tutorials, tutorials, tutorial search, tutorial links, find tutorials, photo shop tutorials, html tutorials,
blog directory Internet Blogs - BlogCatalog Blog Directory
TopOfBlogs