.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Bugs & Resolutions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to Convert Image to Binary String?

Posted By:Sajid P K       Posted Date: October 11, 2010    Points: 15    Category: Bugs & Resolutions    URL: http://www.dotnetspark.com  

Here you will learn How Convert Image to Binary String using of C# and the .NET Framework.
 

Basically, the program "reads" the image pixel by pixel, and where there is a pixel that is something else than white it will Append 1, else 0 in the string.

private string ConvertoToString(string imagePath)

{

string text = "";

System.Drawing.Bitmap bitMap = new Bitmap(imagePath);

for (int i = 0; i < bitMap.Height; i++)

{

for (int j = 0; j < bitMap.Width; j++)

{

if (bitMap.GetPixel(j, i).A.ToString() == "255" && bitMap.GetPixel(j, i).B.ToString() == "255" && bitMap.GetPixel(j, i).G.ToString() == "255" && bitMap.GetPixel(j, i).R.ToString() == "255")

{

text = text + "0";

}

else

{

text = text + "1";

}

}

text = text + "";

}

return ( text);

}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend