Description: In the following lines, you will learn How to create Method to 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); } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|