Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.IO;
- using System.Collections;
- using Microsoft.VisualBasic;
- namespace A4Datasheet
- {
- class MainClass
- {
- public static bool[] data;
- public static int x = 0;
- public static int y = 0;
- public static int lenghtX = 0;
- public static int lenghtY = 0;
- public static byte[] file;
- public static Bitmap sheet;
- public static Size A4;
- public static void Main (string[] args)
- {
- A4 = new Size (595, 841);
- Console.WriteLine ("A4Datasheet");
- Console.WriteLine ("0.01prealpha" + Environment.NewLine + Environment.NewLine + "File to burn:");
- string path = Console.ReadLine ();
- sheet = new Bitmap (A4.Width, A4.Height);
- file = System.IO.File.ReadAllBytes (path);
- int i = 0;
- int a = 0;
- while (i < file.Length) {
- string databin = Convert.ToString(file[i], 2).PadLeft(8, '0');
- char[] datachar = databin.ToCharArray();
- Console.WriteLine("Writing " + file[i]);
- while (a < databin.Length)
- {
- if (datachar[a] == '0')
- {
- DrawLineal (0);
- }
- else if (datachar[a] == '1')
- {
- DrawLineal (1);
- }
- a++;
- }
- i++;
- a = 0;
- }
- DrawLineal (2); // This point tell to the reader when it's time to finish!
- sheet.Save ("data.png");
- }
- public static void DrawLineal (int pixel)
- {
- if (y < sheet.Height) {
- if (x < sheet.Width) {
- if (pixel == 1) {
- sheet.SetPixel (x, y, Color.Black);
- } else {
- sheet.SetPixel (x, y, Color.White);
- }
- if (pixel == 2)
- {
- sheet.SetPixel (x, y, Color.Red);
- }
- x++;
- }
- else
- {
- y++;
- x = 0;
- }
- } else {
- Console.WriteLine ("File is too big! - Impossible to write");
- Console.ReadLine ();
- Environment.Exit(0);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment