Showing posts with label how to retrieve image in console in binary code. Show all posts
Showing posts with label how to retrieve image in console in binary code. Show all posts

Saturday, July 16, 2011

how to retrieve image in console in binary code

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();

        }

    }

}

AngularJS Basics - Part 1

                                                                  AngularJS What is AngularJS ·          Framework by googl...