Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace Images
- {
- class Program
- {
- private const int SquareSize = 512;
- static void Main(string[] args)
- {
- var path = Directory.GetCurrentDirectory();
- var imagesDirectory = path + "\\images\\";
- if (!Directory.Exists(imagesDirectory))
- Directory.CreateDirectory(imagesDirectory);
- Console.WriteLine("Proccecing " + path);
- var directoryPaths = Directory.GetDirectories(path);
- for (int i = 0; i < directoryPaths.Length; i++)
- {
- var directoryPath = directoryPaths[i];
- string[] numbers = Regex.Split(directoryPath, @"\D+");
- if (numbers.Length == 4)
- {
- var index = int.Parse(numbers[1]);
- var width = int.Parse(numbers[2]);
- var height = int.Parse(numbers[3]);
- var imageName = imagesDirectory + index + ".Jpeg";
- if (!File.Exists(imageName))
- {
- Console.WriteLine("Combining: " + directoryPath);
- Combine(directoryPath, width, height, imageName);
- Console.WriteLine("Done");
- }
- else
- Console.WriteLine("Skipping: " + imageName);
- }
- }
- Console.WriteLine("All Done");
- }
- private static void Combine(string path,int width,int height,string outputFile)
- {
- using (Bitmap bmp = new Bitmap(width * SquareSize , height * SquareSize))
- {
- using (Graphics g = Graphics.FromImage(bmp))
- {
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++)
- {
- var index = x + y * width;
- var indexImage = Image.FromFile(path+ "\\" + index + ".png");
- g.DrawImage(indexImage, x * SquareSize, y * SquareSize, SquareSize, SquareSize);
- indexImage.Dispose();
- }
- }
- }
- bmp.Save(outputFile, ImageFormat.Jpeg);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement