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
|
using System.Drawing;
using System.Drawing.Imaging;
/// <summary>
/// Splittet ein Bild in mehrere Einzelteile.
/// </summary>
/// <param name="path">Pfad zu der Bilddatei.</param>
/// <param name="imageX">X-Koordinate</param>
/// <param name="imageY">Y-Koordinate</param>
/// <param name="outputPath">Pfad zu dem Ordner, wo die Bilddateien gespeichert werden.</param>
public static void SplitImage(string path, int imageX, int imageY, string outputPath)
{
Bitmap original = new Bitmap(path);
Rectangle focusRectangle = new Rectangle();
Bitmap destination;
for (int x = 0; x <= imageX - 1; x++)
{
for (int y = 0; y <= imageY - 1; y++)
{
focusRectangle.X = x * (original.Width / imageX);
focusRectangle.Y = y * (original.Height / imageY);
focusRectangle.Height = original.Height / imageX;
focusRectangle.Width = original.Width / imageY;
destination = original.Clone(focusRectangle, PixelFormat.DontCare);
destination.Save(outputPath + @"\im" + x.ToString() + y.ToString() + ".jpg");
}
}
}
|