-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
140 lines (108 loc) · 5.2 KB
/
Copy pathProgram.cs
File metadata and controls
140 lines (108 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using Ascii;
using GraphicsMagick;
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
namespace Font2Image
{
static class Program
{
public static Color Rainbow(float progress)
{
float div = (Math.Abs(progress % 1) * 6);
int ascending = (int)((div % 1) * 255);
int descending = 255 - ascending;
switch ((int)div)
{
case 0:
return Color.FromArgb(255, 255, ascending, 0);
case 1:
return Color.FromArgb(255, descending, 255, 0);
case 2:
return Color.FromArgb(255, 0, 255, ascending);
case 3:
return Color.FromArgb(255, 0, descending, 255);
case 4:
return Color.FromArgb(255, ascending, 0, 255);
default: // case 5:
return Color.FromArgb(255, 255, 0, descending);
}
}
static void Main(string[] args)
{
PrivateFontCollection collection = new PrivateFontCollection();
collection.AddFontFile("OpenSans-Bold.ttf");
var fontFamily = collection.Families[0];
PrivateFontCollection mono = new PrivateFontCollection();
mono.AddFontFile("AnonymousPro-Regular.ttf");
var monoFamily = mono.Families[0];
var ch = (char)0x41;
int n = 1;
//using (var gif = AnimatedGif.AnimatedGif.Create(@"D:\#Ablage\Github\font2image\bin\#ABC.gif", 250))
//using (var magic = new MagickImageCollection())
//{
// for (int i = 1; i <= 26; i++)
// {
// MagickImage img = new MagickImage($@"D:\#Ablage\Github\font2image\bin\{string.Format("{0:00}", i)}L.png");
// img.Quality = 100;
// img.Resize(10);
// img.Draw(new DrawableText(0, 0, "AAAA"));
// var settings = new QuantizeSettings
// {
// Colors = 256
// };
// var err = img.Quantize(settings);
// magic.Add(img);
// magic[n - 1].AnimationDelay = 500;
// Console.WriteLine(i);
// }
// magic.Write(@"D:\#Ablage\Github\font2image\bin\#ABC.gif");
//}
//Console.WriteLine("Fertig");
//Console.ReadLine();
for (int i = ch; i <= 0x5A; i++)
{
//n = 23;
//i = 0x57;
//var magicImage = new MagickImage(Color.White, 4096, 4096);
Bitmap bitmapimage = new Bitmap(4096, 4096);
Graphics bitmapGraphics = Graphics.FromImage(bitmapimage);
bitmapGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, 4096, 4096);
bitmapGraphics.DrawString(((char)i).ToString(), new Font(fontFamily, 2500, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, 0, -600);
bitmapimage.Save($@"D:\#Ablage\Github\font2image\bin\{string.Format("{0:00}", n)}.png", System.Drawing.Imaging.ImageFormat.Png);
Console.WriteLine($"{ string.Format("{0:00}", n) }");
//Bitmap bitmapimage = new Bitmap($@"D:\#Ablage\Github\font2image\bin\{string.Format("{0:00}", n)}.png");
var assciiArt = Converter.ConvertToAsciiArt(bitmapimage, (char)i);
Bitmap Lbitmapimage = new Bitmap(8192, 8192);
Lbitmapimage.SetResolution(600, 600);
Graphics LbitmapGraphics = Graphics.FromImage(Lbitmapimage);
LbitmapGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
LbitmapGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
LbitmapGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
LbitmapGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
LbitmapGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, 8192, 8192);
int lineHeight = 0;
var f = new Font(monoFamily, 30, FontStyle.Regular, GraphicsUnit.Pixel);
float r = 0.5f;
var lines = assciiArt.Split('\n');
var steps = 1 / ((float)lines.Count());
int x = 0;
if ((char)i == 'W')
{
x = -400;
}
foreach (var line in lines)
{
var color = Rainbow(r);
LbitmapGraphics.DrawString(line, f, new SolidBrush(color), x, lineHeight);
lineHeight += 25;
//r += 0.1f;
r += steps;
}
Lbitmapimage.Save($@"D:\#Ablage\Github\font2image\bin\{string.Format("{0:00}", n)}L.png", System.Drawing.Imaging.ImageFormat.Png);
n++;
}
}
}
}