using System;
using System.IO;
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();
}
}
}
Be Different with excellent knowledge A Devloper Blog....
Subscribe to:
Post Comments (Atom)
AngularJS Basics - Part 1
AngularJS What is AngularJS · Framework by googl...
-
Make Your Own Notepad In this tutorial we will be making a simple C# Notepad with the option to Clear, Cut, Copy, Paste, Select All, Save...
-
What is View? A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting r...
No comments:
Post a Comment
Your comment is pending for approval