I have a hundred of JPG image pieces and want to merge them in one large JPG. And to accomplish that I use the following code:
using (var combinedBitmap = new Bitmap(combinedWidth, combinedHeights)) {
combinedBitmap.SetResolution(96, 96);
using (var g = Graphics.FromImage(combinedBitmap))
{
g.Clear(Color.White);
foreach (var imagePiece in imagePieces)
{
var imagePath = Path.Combine(slideFolderPath, imagePiece.FileName);
using (var image = Image.FromFile(imagePath))
{
var x = columnXs[imagePiece.Column];
var y = rowYs[imagePiece.Row];
g.DrawImage(image, new Point(x, y));
}
}
}
combinedBitmap.Save(combinedImagePath, ImageFormat.Jpeg);
}
Everything is fine until dimensions (combinedWidth
, combinedHeights
) exceed curtain threshold like says here https://stackoverflow.com/a/29175905/623190
The merged JPG file with dimensions of 23170 x 23170 pixels is about 50MB — not too big to kill the memory.
But the Bitmap can not be created with greater dimensions — just breaks with the wrong parameter exception.
Is there any other way to merge the JPG image pieces in one large JPG with dimensions greater than 23170 x 23170 using C#?