Saturday, July 16, 2011

convert binary code into image

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace binary_data_converted_into_image
{
    public class DecodeBase64Binary
    {

        public static void Main(string[] args)
        {

            //

            // Read the contents of Encoded Bitmap from the text file.

            //

            TextReader reader = new StreamReader(@"f:\Water lilies.txt");

            String imageString = reader.ReadLine();



            //

            // Decode the Base64-Encoded binary whic previously read from the

            // text file above.

            //

            byte[] imageBytes = Convert.FromBase64String(imageString);



            //

            // Create a new image file.

            //

            FileStream fs = new FileStream(@"C:\New Water lilies.jpg", FileMode.Create, FileAccess.Write);

            BinaryWriter writer = new BinaryWriter(fs);



            try
            {

                for (int i = 0; i < imageBytes.Length; i++)
                {

                    writer.Write(imageBytes[i]);

                }

            }
            finally
            {

                writer.Close();

                fs.Close();

            }



            Console.ReadLine();

        }

    }
}
//--------------

No comments:

Post a Comment

Your comment is pending for approval

AngularJS Basics - Part 1

                                                                  AngularJS What is AngularJS ·          Framework by googl...