Version 3, added Global settings that are saved. Added a Main menu
This commit is contained in:
@@ -33,6 +33,9 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
@@ -50,6 +53,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
189
Program.cs
189
Program.cs
@@ -4,6 +4,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
namespace ConvertTo16x16
|
namespace ConvertTo16x16
|
||||||
{
|
{
|
||||||
@@ -28,43 +31,188 @@ namespace ConvertTo16x16
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
public string FileDir { get; set; }
|
||||||
|
public int PixelAnzahl { get; set; }
|
||||||
|
public bool RmBackground { get; set; }
|
||||||
|
public Color BackgroundCol { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static Settings settings = new Settings();
|
||||||
|
|
||||||
|
static void mainMenu()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Console.WriteLine("[S]tart");
|
||||||
|
Console.WriteLine("S[e]ttings");
|
||||||
|
Console.WriteLine("E[n]d");
|
||||||
|
|
||||||
|
string input = Console.ReadLine();
|
||||||
|
|
||||||
|
switch (input.ToLower())
|
||||||
|
{
|
||||||
|
case "s":
|
||||||
|
if (settings == null || settings.FileDir == null || settings.PixelAnzahl < 16)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You have to edit some Settings before continuing.");
|
||||||
|
Console.ReadKey(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Console.Clear();
|
||||||
|
Start();
|
||||||
|
break;
|
||||||
|
case "e":
|
||||||
|
Console.Clear();
|
||||||
|
Settings();
|
||||||
|
break;
|
||||||
|
case "n":
|
||||||
|
Environment.Exit(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Input not accepted");
|
||||||
|
Console.ReadKey(true);
|
||||||
|
Console.Clear();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
LoadJson();
|
||||||
|
mainMenu();
|
||||||
|
}
|
||||||
|
|
||||||
//C:\Users\zamk\Bilder\RickNice.jpg
|
public static void Settings()
|
||||||
|
{
|
||||||
|
Console.Write("Geben sie den Pfad an : ");
|
||||||
|
if (settings.FileDir != null) {
|
||||||
|
Console.WriteLine($"\nPfad : {settings.FileDir}");
|
||||||
|
Console.SetCursorPosition(25, Console.CursorTop - 2);
|
||||||
|
}
|
||||||
|
settings.FileDir = Console.ReadLine();
|
||||||
|
Console.Write("\nGeben sie an Wieviele Pixel sie wollen (Empfohlen: 16 | 32) : ");
|
||||||
|
if (settings.PixelAnzahl > 15)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"\nPixel Anzahl : {settings.PixelAnzahl}");
|
||||||
|
Console.SetCursorPosition(62, Console.CursorTop - 2);
|
||||||
|
}
|
||||||
|
settings.PixelAnzahl = Convert.ToInt32(Console.ReadLine());
|
||||||
|
Console.WriteLine("\nGeben sie an Ob eine Hintergrundfarbe ignoriert werden soll : ");
|
||||||
|
Console.WriteLine("[T]rue");
|
||||||
|
Console.WriteLine("[F]alse");
|
||||||
|
if (settings.PixelAnzahl > 15)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Remove Background : {settings.RmBackground}");
|
||||||
|
Console.WriteLine($"Color : {settings.BackgroundCol}");
|
||||||
|
Console.SetCursorPosition(63, Console.CursorTop - 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
string input = Console.ReadLine();
|
||||||
|
switch (input.ToLower())
|
||||||
|
{
|
||||||
|
case "t":
|
||||||
|
settings.RmBackground = true;
|
||||||
|
Console.WriteLine("Which Color should be removed");
|
||||||
|
Console.Write("Red : ");
|
||||||
|
int red = Convert.ToInt32(Console.ReadLine());
|
||||||
|
Console.Write("Green : ");
|
||||||
|
int green = Convert.ToInt32(Console.ReadLine());
|
||||||
|
Console.Write("Blue : ");
|
||||||
|
int blue = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
if (red > 255 || green > 255 || blue > 255)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Input not accepted");
|
||||||
|
Console.ReadKey(true);
|
||||||
|
Console.Clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.BackgroundCol = Color.FromArgb(red, green, blue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "f":
|
||||||
|
settings.RmBackground = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Input not accepted");
|
||||||
|
Console.ReadKey(true);
|
||||||
|
Console.Clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadJson()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (StreamReader r = new StreamReader(@"C:\Users\zamk\Documents\MyProjects\16x16\settings.json"))
|
||||||
|
{
|
||||||
|
settings = JsonConvert.DeserializeObject<Settings>(r.ReadToEnd());
|
||||||
|
/*string json = r.ReadToEnd();
|
||||||
|
List<Settings> items = JsonConvert.DeserializeObject<List<Settings>>(json);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader r = new StreamReader(@"C:\Users\zamk\Documents\MyProjects\16x16\settings.json"))
|
||||||
|
{
|
||||||
|
JsonConvert.DeserializeObject<Settings>(r.ReadToEnd());
|
||||||
|
/*string json = r.ReadToEnd();
|
||||||
|
List<Settings> items = JsonConvert.DeserializeObject<List<Settings>>(json);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveJson()
|
||||||
|
{
|
||||||
|
string jsonString = JsonConvert.SerializeObject(settings, Formatting.Indented);
|
||||||
|
File.WriteAllText(@"C:\Users\zamk\Documents\MyProjects\16x16\settings.json", jsonString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void Start()
|
||||||
|
{
|
||||||
Console.Write("Geben sie den Bildnamen an: ");
|
Console.Write("Geben sie den Bildnamen an: ");
|
||||||
string bildName = Console.ReadLine();
|
string bildName = Console.ReadLine();
|
||||||
|
|
||||||
Console.Write("Geben sie den Pfad an: ");
|
Bitmap bmp = new Bitmap($@"{settings.FileDir}\{bildName}");
|
||||||
string Pfad = Console.ReadLine();
|
Bitmap outcome = new Bitmap(settings.PixelAnzahl, settings.PixelAnzahl);
|
||||||
|
int Width = bmp.Width / settings.PixelAnzahl;
|
||||||
//string Pfad = @"D:\Pictures16";
|
int Height = bmp.Height / settings.PixelAnzahl;
|
||||||
//string bildName = "RickNice.jpg";
|
|
||||||
int PixelAnzahl = 16;
|
|
||||||
|
|
||||||
Bitmap bmp = new Bitmap($@"{Pfad}\{bildName}");
|
|
||||||
Bitmap outcome = new Bitmap(PixelAnzahl, PixelAnzahl);
|
|
||||||
int Width = bmp.Width / PixelAnzahl;
|
|
||||||
int Height = bmp.Height / PixelAnzahl;
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
Console.Write("Performing some task... ");
|
Console.Write("Berechnen... ");
|
||||||
using (var progress = new ProgressBar())
|
using (var progress = new ProgressBar())
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PixelAnzahl; i++)
|
for (int i = 0; i < settings.PixelAnzahl; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < PixelAnzahl; j++)
|
for (int j = 0; j < settings.PixelAnzahl; j++)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<Count> Argb = new List<Count>();
|
List<Count> Argb = new List<Count>();
|
||||||
|
|
||||||
for (int x = Width * i; x < Width * (i + 1); x++)
|
for (int x = Convert.ToInt32(Math.Ceiling((double)Width * i)); x < Math.Ceiling((double)Width * (i + 1)); x++)
|
||||||
{
|
{
|
||||||
for (int y = Height * j; y < Height * (j + 1); y++)
|
for (int y = Convert.ToInt32(Math.Ceiling((double)Height * j)); y < Math.Ceiling((double)Height * (j + 1)); y++)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool Exists = false;
|
bool Exists = false;
|
||||||
@@ -84,7 +232,7 @@ namespace ConvertTo16x16
|
|||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
double report = Convert.ToDouble(counter) / Convert.ToDouble(16 * 16 * Width * Height);
|
double report = Convert.ToDouble(counter) / Convert.ToDouble(settings.PixelAnzahl * settings.PixelAnzahl * Width * Height);
|
||||||
|
|
||||||
progress.Report(report);
|
progress.Report(report);
|
||||||
}
|
}
|
||||||
@@ -108,8 +256,9 @@ namespace ConvertTo16x16
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outcome.Save($@"{Pfad}\16x16{bildName}");
|
outcome.Save($@"{settings.FileDir}\16x16{bildName}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
BIN
bin/Debug/Newtonsoft.Json.dll
Normal file
BIN
bin/Debug/Newtonsoft.Json.dll
Normal file
Binary file not shown.
11262
bin/Debug/Newtonsoft.Json.xml
Normal file
11262
bin/Debug/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load Diff
0
obj/Debug/ConvertTo16x16.csproj.CopyComplete
Normal file
0
obj/Debug/ConvertTo16x16.csproj.CopyComplete
Normal file
@@ -4,3 +4,6 @@ C:\Users\zamk\source\repos\ConvertTo16x16\bin\Debug\ConvertTo16x16.pdb
|
|||||||
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.csprojAssemblyReference.cache
|
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.csprojAssemblyReference.cache
|
||||||
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.exe
|
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.exe
|
||||||
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.pdb
|
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.pdb
|
||||||
|
C:\Users\zamk\source\repos\ConvertTo16x16\bin\Debug\Newtonsoft.Json.dll
|
||||||
|
C:\Users\zamk\source\repos\ConvertTo16x16\bin\Debug\Newtonsoft.Json.xml
|
||||||
|
C:\Users\zamk\source\repos\ConvertTo16x16\obj\Debug\ConvertTo16x16.csproj.CopyComplete
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
packages.config
Normal file
4
packages.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
|
||||||
|
</packages>
|
||||||
BIN
packages/Newtonsoft.Json.12.0.3/.signature.p7s
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/.signature.p7s
vendored
Normal file
Binary file not shown.
20
packages/Newtonsoft.Json.12.0.3/LICENSE.md
vendored
Normal file
20
packages/Newtonsoft.Json.12.0.3/LICENSE.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2007 James Newton-King
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
BIN
packages/Newtonsoft.Json.12.0.3/Newtonsoft.Json.12.0.3.nupkg
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/Newtonsoft.Json.12.0.3.nupkg
vendored
Normal file
Binary file not shown.
BIN
packages/Newtonsoft.Json.12.0.3/lib/net20/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/net20/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
10298
packages/Newtonsoft.Json.12.0.3/lib/net20/Newtonsoft.Json.xml
vendored
Normal file
10298
packages/Newtonsoft.Json.12.0.3/lib/net20/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/net35/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/net35/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
9446
packages/Newtonsoft.Json.12.0.3/lib/net35/Newtonsoft.Json.xml
vendored
Normal file
9446
packages/Newtonsoft.Json.12.0.3/lib/net35/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/net40/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/net40/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
9646
packages/Newtonsoft.Json.12.0.3/lib/net40/Newtonsoft.Json.xml
vendored
Normal file
9646
packages/Newtonsoft.Json.12.0.3/lib/net40/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/net45/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/net45/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
11262
packages/Newtonsoft.Json.12.0.3/lib/net45/Newtonsoft.Json.xml
vendored
Normal file
11262
packages/Newtonsoft.Json.12.0.3/lib/net45/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.0/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.0/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
10950
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.0/Newtonsoft.Json.xml
vendored
Normal file
10950
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.0/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.3/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.3/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
11072
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.3/Newtonsoft.Json.xml
vendored
Normal file
11072
packages/Newtonsoft.Json.12.0.3/lib/netstandard1.3/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
11237
packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.xml
vendored
Normal file
11237
packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
9010
packages/Newtonsoft.Json.12.0.3/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
9010
packages/Newtonsoft.Json.12.0.3/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
10950
packages/Newtonsoft.Json.12.0.3/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
10950
packages/Newtonsoft.Json.12.0.3/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.12.0.3/packageIcon.png
vendored
Normal file
BIN
packages/Newtonsoft.Json.12.0.3/packageIcon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.7 KiB |
Reference in New Issue
Block a user