using System;
using System.IO;
using System.Drawing;
namespace ImageToBase64
{
class Program
{
static void Main(string[] args)
{
using(System.Drawing.Image i = (Image)Bitmap.FromFile(@"c:\test\TMC_logo_2.jpg"))
{
using(MemoryStream ms = new MemoryStream())
{
i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = ms.ToArray();
string s = Convert.ToBase64String(bytes);
using(TextWriter tw = new StreamWriter(@"c:\test\string.txt"))
{
tw.WriteLine(string.Format(@"", s));
}
}
}
}
}
}
Monday, 18 April 2011
Encoding images into HTML using C#
Here's a sample that converts a jpeg into an imline image tag...
Subscribe to:
Posts (Atom)