470,815 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Ways to convert an image to base64 and back

The following code is the current method i have for converting an image
to Base64.Is this the most efficient way to convert an image to base64
or are there others. The Image class's Save method is slow here and i am
wondering if i can do it some other way to make it faster.....Any ideas

public string ImageToBase64String(Image imageData ImageFormat format)
{
string base64;
MemoryStream memory = new MemoryStream();
imageData.Save(memory, format);
base64 = System.Convert.ToBase64String(memory.ToArray());
memory.Close();
memory = null;

return base64;
}
*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
1 20840
Using the memorystream is the fastest way. I saw that there is a little
nifty private field called rawData wich contains a byte[] representation of
the image. If only this field was public you could immediatly call the
System.Convert.ToBase64String() passing this field :(

Gabriel Lozano-Morán

<James dean> wrote in message news:em**************@TK2MSFTNGP15.phx.gbl...
The following code is the current method i have for converting an image
to Base64.Is this the most efficient way to convert an image to base64
or are there others. The Image class's Save method is slow here and i am
wondering if i can do it some other way to make it faster.....Any ideas

public string ImageToBase64String(Image imageData ImageFormat format)
{
string base64;
MemoryStream memory = new MemoryStream();
imageData.Save(memory, format);
base64 = System.Convert.ToBase64String(memory.ToArray());
memory.Close();
memory = null;

return base64;
}
*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by marcelo szwarc via .NET 247 | last post: by
1 post views Thread by Swarup | last post: by
2 posts views Thread by VenuGopal | last post: by
7 posts views Thread by David Thielen | last post: by
29 posts views Thread by Harlin Seritt | last post: by
6 posts views Thread by Bob Altman | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.