<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tutorials Archive &#187; Programming</title>
	<atom:link href="http://tutarchive.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://tutarchive.com</link>
	<description>Save and Share your Tutorials</description>
	<lastBuildDate>Thu, 04 Feb 2010 02:51:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Convert Image to Base64 String and Base64 String to Image</title>
		<link>http://tutarchive.com/2009/09/convert-image-to-base64-string-and-base64-string-to-image/</link>
		<comments>http://tutarchive.com/2009/09/convert-image-to-base64-string-and-base64-string-to-image/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 15:40:09 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=183</guid>
		<description><![CDATA[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&#40;Image image, 
  System.Drawing.Imaging.ImageFormat format&#41;
&#123;
  using &#40;MemoryStream ms = new MemoryStream&#40;&#41;&#41;
  &#123;
    // Convert Image to byte[]
    image.Save&#40;ms, format&#41;;
 [...]


Related posts:<ol><li><a href='http://tutarchive.com/2009/09/see-what-any-site-looks-like-in-ie6/' rel='bookmark' title='Permanent Link: See what any site looks like in IE6'>See what any site looks like in IE6</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>This article will help you to learn how we can convert an image into a base64 string and base64 string back to image.</p>
<p><strong>Image to Base64 String</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> ImageToBase64<span style="color: #000000;">&#40;</span>Image image, 
  <span style="color: #000000;">System.<span style="color: #0000FF;">Drawing</span>.<span style="color: #0000FF;">Imaging</span></span>.<span style="color: #0000FF;">ImageFormat</span> format<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>MemoryStream ms <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Convert Image to byte[]</span>
    image.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span>ms, format<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> imageBytes <span style="color: #008000;">=</span> ms.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Convert byte[] to Base64 String</span>
    <span style="color: #FF0000;">string</span> base64String <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToBase64String</span><span style="color: #000000;">&#40;</span>imageBytes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">return</span> base64String<span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><span id="more-183"></span><br />
<strong>Base64 String to Image</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> Image Base64ToImage<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> base64String<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// Convert Base64 String to byte[]</span>
  <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> imageBytes <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">FromBase64String</span><span style="color: #000000;">&#40;</span>base64String<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  MemoryStream ms <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryStream<span style="color: #000000;">&#40;</span>imageBytes, <span style="color: #FF0000;">0</span>, 
    imageBytes.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// Convert byte[] to Image</span>
  ms.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>imageBytes, <span style="color: #FF0000;">0</span>, imageBytes.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  Image image <span style="color: #008000;">=</span> Image.<span style="color: #0000FF;">FromStream</span><span style="color: #000000;">&#40;</span>ms, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">return</span> image<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://tutarchive.com/2009/09/see-what-any-site-looks-like-in-ie6/' rel='bookmark' title='Permanent Link: See what any site looks like in IE6'>See what any site looks like in IE6</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/convert-image-to-base64-string-and-base64-string-to-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
