-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathProgram.cs
More file actions
205 lines (177 loc) · 6.3 KB
/
Program.cs
File metadata and controls
205 lines (177 loc) · 6.3 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
namespace TestAppNet461
{
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using Kaliko.ImageLibrary;
using Kaliko.ImageLibrary.FastFilters;
using Kaliko.ImageLibrary.Scaling;
class Program
{
private static string AppPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
private static string ImagePath = Path.GetFullPath(AppPath + "\\..\\..\\vincent-guth-183404-unsplash.jpg"); // Sample photo by Vincent Guth @vingtcent
private static string OutputPath = Path.GetFullPath(AppPath + "\\..\\..\\output/");
static void Main(string[] args)
{
Console.WriteLine("Demo application for .NET Image Library [.NET 4.61]");
// Scaling
CropScale();
FitScale();
FocalPointScale();
PadScale();
// Filters
Brightness();
ChromaKey();
Contrast();
Desaturate();
GaussianBlur();
Invert();
UnsharpMask();
// Functions
DrawText();
GradientFill();
Watermark();
}
#region Scaling
private static void CropScale()
{
using (var image = new KalikoImage(ImagePath))
{
image
.Scale(new CropScaling(500, 500))
.SaveJpg($"{OutputPath}cropscale.jpg", 80);
}
}
private static void FitScale()
{
using (var image = new KalikoImage(ImagePath))
{
image
.Scale(new FitScaling(500, 500))
.SaveJpg($"{OutputPath}fitscale.jpg", 80);
}
}
private static void PadScale()
{
using (var image = new KalikoImage(ImagePath))
{
image
.Scale(new PadScaling(500, 500, Color.Crimson))
.SaveJpg($"{OutputPath}padscale.jpg", 80);
}
}
private static void FocalPointScale()
{
using (var image = new KalikoImage(ImagePath))
{
image
.Scale(new FocalPointScaling(500, 500, 1, 1))
.SaveJpg($"{OutputPath}focalpointscale.jpg", 80);
}
}
#endregion Scaling
#region Filters
// Note: Unless your application is running in medium trust environment, always use the FastFilters-version of the filter
private static void Brightness()
{
using (var image = new KalikoImage(ImagePath))
{
image.ApplyFilter(new FastBrightnessFilter(50));
image.SaveJpg($"{OutputPath}brightness.jpg", 80);
}
}
private static void Contrast()
{
using (var image = new KalikoImage(ImagePath))
{
image.ApplyFilter(new FastContrastFilter(50));
image.SaveJpg($"{OutputPath}contrast.jpg", 80);
}
}
private static void ChromaKey()
{
using (var image = new KalikoImage(Path.GetFullPath(AppPath + "\\..\\..\\jcvd-green-screen.jpg")))
{
image.ApplyFilter(new FastChromaKeyFilter(Color.FromArgb(13, 161, 37), 40, 0.5f, 0.75f));
image.SavePng($"{OutputPath}chromakey.png");
using (var background = new KalikoImage(ImagePath))
{
var scaledBackground = background.Scale(new FocalPointScaling(640, 320, 0, 1));
scaledBackground.BlitImage(image);
scaledBackground.SaveJpg($"{OutputPath}chromakey.jpg", 80);
}
}
}
private static void Desaturate()
{
using (var image = new KalikoImage(ImagePath))
{
image.ApplyFilter(new FastDesaturationFilter());
image.SaveJpg($"{OutputPath}desaturate.jpg", 80);
}
}
private static void GaussianBlur()
{
using (var image = new KalikoImage(ImagePath))
{
image.ApplyFilter(new FastGaussianBlurFilter(1.1f));
image.SaveJpg($"{OutputPath}gaussianblur.jpg", 80);
}
}
private static void Invert()
{
using (var image = new KalikoImage(ImagePath))
{
image.ApplyFilter(new FastInvertFilter());
image.SaveJpg($"{OutputPath}invert.jpg", 80);
}
}
private static void UnsharpMask()
{
using (var image = new KalikoImage(ImagePath))
{
image.ApplyFilter(new FastUnsharpMaskFilter(1.1f, 0.44f, 0));
image.SaveJpg($"{OutputPath}unsharpmask.jpg", 80);
}
}
#endregion Filters
#region Functions
private static void DrawText()
{
using (var image = new KalikoImage(ImagePath))
{
var text = new TextField("Lorem ipsum")
{
Alignment = StringAlignment.Center,
VerticalAlignment = StringAlignment.Center,
Outline = 5,
OutlineColor = Color.Red,
Font = new Font("Arial", 60),
Rotation = 30f,
TextColor = Color.DarkOrange,
TextShadow = new TextShadow(Color.FromArgb(128, 0, 0, 0), 4, 4)
};
image.DrawText(text);
image.SaveJpg($"{OutputPath}text.jpg", 80);
}
}
private static void GradientFill()
{
using (var image = new KalikoImage(ImagePath))
{
image.GradientFill(Color.FromArgb(128, 255, 200, 90), Color.FromArgb(128, 255, 64, 0));
image.SaveJpg($"{OutputPath}gradientfill.jpg", 80);
}
}
private static void Watermark()
{
using (var image = new KalikoImage(ImagePath))
{
image.BlitFill(Path.GetFullPath(AppPath + "\\..\\..\\watermark.png"));
image.SaveJpg($"{OutputPath}watermark.jpg", 80);
}
}
#endregion Functions
}
}