public char[] GetText() { string ret = ""; int msgSize = this.GetMsgSize(); int numOfBits = msgSize * 8; List <bool> bits = new List <bool>(); byte[] bytes; Color clr = new Color(); bool done = false; for (int i = this.w; i < this.bmp.Width; i++) { for (int j = this.h + 1; j < this.bmp.Height; j++) { if (numOfBits < 3) { clr = this.bmp.GetPixel(i, j); if (numOfBits == 2) { bits.Add(BitManipulator.GetBit(clr.R, 1)); bits.Add(BitManipulator.GetBit(clr.G, 1)); } else if (numOfBits == 1) { bits.Add(BitManipulator.GetBit(clr.R, 1)); } done = true; numOfBits -= 3; break; } else { clr = this.bmp.GetPixel(i, j); bits.Add(BitManipulator.GetBit(clr.R, 1)); bits.Add(BitManipulator.GetBit(clr.G, 1)); bits.Add(BitManipulator.GetBit(clr.B, 1)); numOfBits -= 3; } } if (done) { break; } } //bytes = BitManipulator.BoolToByte(bits.ToArray()); //char[] charArray = Encoding.ASCII.GetString(bytes).ToCharArray(); //Array.Reverse(charArray); byte[] ints = BitManipulator.BoolToByte(bits.ToArray()); //char[] chars = BitManipulator.IntsToChar(ints); char[] chars = BitManipulator.BytesToChars(ints); Array.Reverse(chars); return(chars); }
public int GetMsgSize() { List <bool> bits = new List <bool>(); bool done = false; int count = 0; Color clr; int i = 0, j = 0; for (i = 0; i < bmp.Width; i++) { for (j = 0; j < bmp.Height; j++) { clr = bmp.GetPixel(i, j); if (count == 30) { bits.Add(BitManipulator.GetBit(clr.R, 1)); bits.Add(BitManipulator.GetBit(clr.G, 1)); done = true; break; } else { clr = bmp.GetPixel(i, j); bits.Add(BitManipulator.GetBit(clr.R, 1)); bits.Add(BitManipulator.GetBit(clr.G, 1)); bits.Add(BitManipulator.GetBit(clr.B, 1)); count += 3; } } if (done) { break; } } //byte[] bytes = BitManipulator.BoolToByte(bits.ToArray()); this.w = i; this.h = j; return(BitManipulator.BoolToInt(bits.ToArray())[0]); }