From faddabc598fa5de3e62e05bd65692945e6f2b619 Mon Sep 17 00:00:00 2001 From: Cactus Date: Thu, 11 Aug 2016 23:21:32 -0400 Subject: [PATCH] Initial commit --- .gitignore | 2 + BinaryToImage.sln | 20 ++++++++ BinaryToImage/App.config | 6 +++ BinaryToImage/BinaryToImage.csproj | 59 +++++++++++++++++++++ BinaryToImage/Program.cs | 65 ++++++++++++++++++++++++ BinaryToImage/Properties/AssemblyInfo.cs | 36 +++++++++++++ 6 files changed, 188 insertions(+) create mode 100644 .gitignore create mode 100644 BinaryToImage.sln create mode 100644 BinaryToImage/App.config create mode 100644 BinaryToImage/BinaryToImage.csproj create mode 100644 BinaryToImage/Program.cs create mode 100644 BinaryToImage/Properties/AssemblyInfo.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfc8215 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +BinaryToImage/bin/ +BinaryToImage/obj/ diff --git a/BinaryToImage.sln b/BinaryToImage.sln new file mode 100644 index 0000000..a9a75cc --- /dev/null +++ b/BinaryToImage.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryToImage", "BinaryToImage\BinaryToImage.csproj", "{3EEE7B13-5C6F-4E7C-8613-0BC402656A2C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3EEE7B13-5C6F-4E7C-8613-0BC402656A2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3EEE7B13-5C6F-4E7C-8613-0BC402656A2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3EEE7B13-5C6F-4E7C-8613-0BC402656A2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3EEE7B13-5C6F-4E7C-8613-0BC402656A2C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/BinaryToImage/App.config b/BinaryToImage/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/BinaryToImage/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BinaryToImage/BinaryToImage.csproj b/BinaryToImage/BinaryToImage.csproj new file mode 100644 index 0000000..4baa0bf --- /dev/null +++ b/BinaryToImage/BinaryToImage.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {3EEE7B13-5C6F-4E7C-8613-0BC402656A2C} + Exe + Properties + BinaryToImage + BinaryToImage + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BinaryToImage/Program.cs b/BinaryToImage/Program.cs new file mode 100644 index 0000000..078cf90 --- /dev/null +++ b/BinaryToImage/Program.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BinaryToImage +{ + class Program + { + static void Main(string[] args) + { + if (args.Length != 2) + { + Console.WriteLine("Usage: BinaryToImage.exe [BitTextFile] [ImageFilename]"); + return; + } + + var outputImage = args[1]; + + var bitsLines = File.ReadAllLines(args[0]) + .Select(x => x.Replace(" ", "")) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .ToList(); + + var black = new SolidBrush(Color.Black); + var white = new SolidBrush(Color.White); + + var width = bitsLines.Max(x => x.Length) * 8; + var height = bitsLines.Count(x => !string.IsNullOrWhiteSpace(x))*8; + var bmp = new Bitmap(width, height); + var g = Graphics.FromImage(bmp); + + for (var y = 0; y < bitsLines.Count; y++) + { + var line = bitsLines[y]; + for (var x = 0; x < line.Length; x++) + { + var c = line[x]; + var color = c == '0' ? black : white; + g.FillRectangle(color, x * 8, y * 8, 8f, 8f); + } + } + + ImageFormat format; + + switch (Path.GetExtension(outputImage).ToLower()) + { + case "jpeg": + case "jpg": + format = ImageFormat.Jpeg; + break; + default: + format = ImageFormat.Png; + break; + + } + + bmp.Save(outputImage, format); + } + } +} diff --git a/BinaryToImage/Properties/AssemblyInfo.cs b/BinaryToImage/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..461f59b --- /dev/null +++ b/BinaryToImage/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("BinaryToImage")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BinaryToImage")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e43c06e8-5acc-4c8f-b645-84cfa2598765")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]