static void convertBitmap(string inputFile, string outputFile) { Image im = Bitmap.FromFile(inputFile); Bitmap b = new Bitmap(im); using (FileStream of = new FileStream(outputFile, FileMode.Create)) using (BinaryWriter bw = new BinaryWriter(of)) { bw.Write(MagicCodeBitmap); bw.Write(b.Width); bw.Write(b.Height); UInt32[] bitmapData = new UInt32[(b.Width * b.Height + 31) / 32]; BitStreamer bs = new BitStreamer(bitmapData); for (int y = 0; y != b.Height; ++y) { for (int x = 0; x != b.Width; ++x) { if (b.GetPixel(x, y).B < 200) { bs.PutBits(1, 1); } else { bs.PutBits(0, 1); } } } foreach (var word in bitmapData) { bw.Write(word); } } }
static void convertBitmap(string inputFile, string outputFile) { Image im = Bitmap.FromFile(inputFile); Bitmap b = new Bitmap(im); using (FileStream of = new FileStream(outputFile, FileMode.Create)) using (BinaryWriter bw = new BinaryWriter(of)) { bw.Write(MagicCodeBitmap); bw.Write(b.Width); bw.Write(b.Height); UInt32[] bitmapData = new UInt32[(b.Width * b.Height + 31) / 32]; BitStreamer bs = new BitStreamer(bitmapData); for (int y = 0; y != b.Height; ++y) { for (int x = 0; x != b.Width; ++x) { if (b.GetPixel(x, y).B < 200) bs.PutBits(1, 1); else bs.PutBits(0, 1); } } foreach (var word in bitmapData) bw.Write(word); } }