Guest User

Untitled

a guest
Sep 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.IO;
  4. using System.Collections;
  5. using Microsoft.VisualBasic;
  6.  
  7. namespace A4Datasheet
  8. {
  9.     class MainClass
  10.     {
  11.         public static bool[] data;
  12.         public static int x = 0;
  13.         public static int y = 0;
  14.         public static int lenghtX = 0;
  15.         public static int lenghtY = 0;
  16.         public static byte[] file;
  17.         public static Bitmap sheet;
  18.         public static Size A4;
  19.         public static void Main (string[] args)
  20.         {
  21.             A4 = new Size (595, 841);
  22.             Console.WriteLine ("A4Datasheet");
  23.             Console.WriteLine ("0.01prealpha" + Environment.NewLine + Environment.NewLine + "File to burn:");
  24.             string path = Console.ReadLine ();
  25.             sheet = new Bitmap (A4.Width, A4.Height);
  26.             file = System.IO.File.ReadAllBytes (path);
  27.  
  28.             int i = 0;
  29.             int a = 0;
  30.  
  31.             while (i < file.Length) {
  32.                 string databin = Convert.ToString(file[i], 2).PadLeft(8, '0');
  33.                 char[] datachar = databin.ToCharArray();
  34.                 Console.WriteLine("Writing " + file[i]);
  35.                 while (a < databin.Length)
  36.                 {
  37.  
  38.                     if (datachar[a] == '0')
  39.                     {
  40.                         DrawLineal (0);
  41.  
  42.                     }
  43.                     else if (datachar[a] == '1')
  44.                     {
  45.                         DrawLineal (1);
  46.                     }
  47.                     a++;
  48.                 }
  49.                 i++;
  50.                 a = 0;
  51.             }
  52.  
  53.             DrawLineal (2); // This point tell to the reader when it's time to finish!
  54.             sheet.Save ("data.png");
  55.         }
  56.  
  57.         public static void DrawLineal (int pixel)
  58.         {
  59.             if (y < sheet.Height) {
  60.                
  61.                 if (x < sheet.Width) {
  62.                     if (pixel == 1) {
  63.                         sheet.SetPixel (x, y, Color.Black);
  64.                     } else {
  65.                         sheet.SetPixel (x, y, Color.White);
  66.                     }
  67.  
  68.                     if (pixel == 2)
  69.                     {
  70.                         sheet.SetPixel (x, y, Color.Red);
  71.                     }
  72.  
  73.                     x++;
  74.                 }
  75.                 else
  76.                 {
  77.                     y++;
  78.                     x = 0;
  79.                 }
  80.  
  81.             } else {
  82.                 Console.WriteLine ("File is too big! - Impossible to write");
  83.                 Console.ReadLine ();
  84.                 Environment.Exit(0);
  85.             }
  86.         }
  87.  
  88.     }
  89. }
Add Comment
Please, Sign In to add comment