/
Program.cs
59 lines (51 loc) · 1.82 KB
/
Program.cs
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
using System;
using System.Drawing;
using System.IO;
namespace Alpha2GreyscaleCore
{
class Program
{
static string imagepath;
static void Main(string[] args)
{
Console.WriteLine("Alpha2Greyscale by rob5300:");
if (args.Length >= 1)
{
imagepath = args[0];
}
else
{
Console.WriteLine("No argument given! Exiting...");
return;
}
try
{
Bitmap image = new Bitmap(imagepath);
Bitmap convertedImage = new Bitmap(image.Width, image.Height);
if (image != null)
{
//Process the image. take the alpha component and create a new image.
for (int x = 0; x < image.Width; x++)
{
for (int y = 0; y < image.Height; y++)
{
Color pixel = image.GetPixel(x, y);
Color newColor = Color.FromArgb(pixel.A, pixel.A, pixel.A);
convertedImage.SetPixel(x, y, newColor);
}
}
//We are done. Save the image.
//Fix the filename to be without the extension
string newPath = Path.GetDirectoryName(imagepath) + "/" + Path.GetFileNameWithoutExtension(imagepath) + "Converted.png";
convertedImage.Save(newPath, image.RawFormat);
Console.WriteLine("Converted image saved to: " + newPath);
}
}
catch (Exception e)
{
Console.WriteLine("Conversion failed: " + e.Message);
}
Console.ReadKey();
}
}
}