static string loadText(string path)
{
Bitmap bm = null;
using (Image img = Image.FromFile(path))
{
bm = new Bitmap(img);
}
BitmapData data = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
BitArray a = new BitArray(bm.Width * bm.Height * 3 / 8 * 8);
unsafe
{
for (int y = 0; y < bm.Height; ++y)
{
byte *p = (byte*)data.Scan0.ToPointer() + data.Stride * y;
for (int x = 0; x < bm.Width; ++x)
{
int bitArrayIdx = (y * bm.Width + x) * 3;
if (bitArrayIdx < a.Length) a[bitArrayIdx] = (p[0] & 1) == 1;
++bitArrayIdx;
if (bitArrayIdx < a.Length) a[bitArrayIdx] = (p[1] & 1) == 1;
++bitArrayIdx;
if (bitArrayIdx < a.Length) a[bitArrayIdx] = (p[2] & 1) == 1;
p += 3;
}
}
}
bm.UnlockBits(data);
byte[] bytes = new byte[bm.Width * bm.Height * 3 / 8];
a.CopyTo(bytes, 0);
bool yes = bytes.Take(4).Select((v, i) => v == HEADER[i]).All(i => i);
if (!yes) return "";
bm.Dispose();
bytes = bytes.Skip(4).ToArray();
bytes = bytes.Take(Array.IndexOf(bytes, (byte)0)).ToArray();
return Encoding.Default.GetString(bytes);
}