
namespace csharp.Example.System
{
public class BinaryToBase64
{
public static void Main(string[] args)
{
//
// Prepare a place holder for our image file
//
byte[] imageBytes = null;
//
// Read the content of image file and store each byte in the
// imagesBytes.
//
FileStream fs = new FileStream(@"C:\Users\Radhey Radhey\Pictures\Cars\1.jpg", FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fs);
try
{
long size = reader.BaseStream.Length;
imageBytes = new byte[size];
for (long i = 0; i < size; i++)
{
imageBytes[i] = reader.ReadByte();
}
}
finally
{
reader.Close();
fs.Close();
}
//
// Convert the images bytes into its equivalent string representation
// encoded with base 64 digit.
//
string imageString = Convert.ToBase64String(imageBytes);
Console.WriteLine("Image String: " + imageString);
TextWriter writer = new StreamWriter(@"f:\Water lilies.txt");
writer.WriteLine(imageString);
Console.ReadLine();
}
}
}
No comments:
Post a Comment
Your comment is pending for approval