-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageGenerator.cs
81 lines (63 loc) · 1.69 KB
/
ImageGenerator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
namespace ImageGenerator {
using System.IO;
using SkiaSharp;
/***/
public class ImageGenerator {
private static int imageWidth = 1000;
private Random random;
private ulong folderNo = 0;
private ulong imageNo = 0;
/***/
public static void Main(string[] args) {
if(args.Length > 0 && args[0].Equals("all")) {
new ImageGenerator(true);
}
else if(args.Length > 0 && args[0].Equals("test")) {
new ImageGenerator(false);
}
else {
Console.WriteLine("Run with a parameter 'all' to create all images or with 'test' to create 10 test images.");
}
}
/***/
public ImageGenerator(bool createAll) {
random = new Random();
if(createAll) {
while(true) {
createImage();
}
}
else {
for(int i = 0; i < 10; i++) {
createImage();
}
}
}
/***/
private void createImage() {
SKBitmap bitmap = new SKBitmap(imageWidth, imageWidth);
using SKCanvas canvas = new SKCanvas(bitmap);
SKPoint point = new SKPoint();
byte[] rgb = new byte[3];
for(int i = 0; i < imageWidth; i++) {
for(int j = 0; j < imageWidth; j++) {
point.X = i;
point.Y = j;
random.NextBytes(rgb);
SKColor color = new SKColor(rgb[0], rgb[1], rgb[2]);
canvas.DrawPoint(point, color);
}
}
Directory.CreateDirectory("" + folderNo);
string imageName = folderNo + "/" + imageNo + ".png";
imageNo++;
if(imageNo == ulong.MaxValue) {
folderNo++;
imageNo = 0;
}
using FileStream fileStream = new FileStream(imageName, FileMode.Create, FileAccess.Write);
using SKImage image = SKImage.FromBitmap(bitmap);
using SKData data = image.Encode();
data.SaveTo(fileStream);
}
}}