Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace BitmapRLEGenerator
- {
- class Program
- {
- public static int ResX = 1000;
- public static int ResY = 1000;
- static void Main(string[] args)
- {
- FileStream bmp = new FileStream("bmp.bmp", FileMode.Create, FileAccess.ReadWrite);
- bmp.Write(new byte[2] { 0x42, 0x4D }); //"BM"
- List<byte> bbb = new List<byte>();
- int CommandAmountPerLine = ResX / 0xFF; if (CommandAmountPerLine * 0xFF != ResX) { CommandAmountPerLine++; }
- for (int i = 0; i < ResY; i++)
- {
- for (int z = 1; z < CommandAmountPerLine+1; z++)
- {
- if (ResX - (z * 255) > 0)
- {
- bbb.Add(0xFF);
- bbb.Add(0xFF);
- } else
- {
- bbb.Add((byte)(ResX % 0xFF));
- bbb.Add(0xFF);
- }
- }
- bbb.Add(0x00);
- bbb.Add(0x00);
- }
- bbb.RemoveRange(bbb.Count - 2, 2);
- bbb.Add(0x00);
- bbb.Add(0x01);
- int BmpSize = 54 + bbb.Count;
- bmp.Write(Bi(BmpSize)); //entire file size
- bmp.Write(Bi(0)); //unused
- bmp.Write(Bi(54)); //offset where bmp data is
- bmp.Write(Bi(40)); //size of DIB header
- bmp.Write(Bi(ResX));
- bmp.Write(Bi(ResY));
- bmp.Write(Bi(524289)); //plane count and bits per color
- bmp.Write(Bi(1)); //rle encoding used
- bmp.Write(Bi(bbb.Count)); //size of bmp data
- bmp.Write(Bi(2835)); //Some printer info idk
- bmp.Write(Bi(2835)); //Some printer info idk
- bmp.Write(Bi(256)); //color stuff
- bmp.Write(Bi(256)); //color stuff
- bmp.Write(bbb.ToArray());
- bmp.Flush();
- }
- private static byte[] Bi(int z)
- {
- return BitConverter.GetBytes(z);
- }
- }
- }
Add Comment
Please, Sign In to add comment