Ich habe Tiles von Karten und möchte diese zu einem einzelnen Bild zusammenfügen. Jedes Tile hat eine Auflösung von 256 x 256 Pixeln. Es soll ein PNG sein. Dazu habe ich Bitmaps genutzt, diese stoßen aber nun an ihre Grenzen. Bis zu einer gewissen Auflösung funktioniert das einwandfrei. Das ist der Code:
Bitmap merged = new Bitmap(width, height);
using (Graphics graphics = Graphics.FromImage(merged))
{
for (int x = 0; x < this.Bounds[1] - this.Bounds[0] + 1; x++)
{
for (int y = 0; y < this.Bounds[3] - this.Bounds[2] + 1; y++)
{
Image image = Image.FromFile(string.Format("{0}{1}-{2}.png", tilePath, x, y));
graphics.DrawImage(image, x * 256, y * 256);
image.Dispose();
}
}
merged.Save(string.Format("{0}\\map.png-merging", outputPath), System.Drawing.Imaging.ImageFormat.Png);
}
File.Move(string.Format("{0}\\map.png-merging", outputPath), string.Format("{0}\\map.png", outputPath));
Es geht bis zur Auflösung 10, bei der es 58 x 56 Tiles, also 14.848 x 14.336 Pixel gibt.
Danach sind es 97 x 110 Tiles, also 24.832 x 28.160 Pixel. Hier kommt es zu einem Fehler. Bei
Bitmap merged = new Bitmap(width, height);
gibt es eine ArgumentException. Ich habe gelesen, dass das Limit für Bitmaps gibt, das ich hier anscheinend überschreibe.
Wie kann ich die Tiles am besten zu einer sehr großen PNG zusammenfügen, außer damit, die PNG mit einem FileStream Byte für Byte selbst zu erstellen?