I'm trying to combine multiple images into one in c# using Bitmap ,my image width is 5000 and height is 1800 (which is constant) as per my code I'm able to combine upto 12 images (the total width will be 60000 and 1800 height).I have total 68 images to combine.I'm getting "Generic Error" when saving the image(error occurs when trying to combine more than 12 images). Final output should be combining the 68 images with (350000 width* 1800 height).
I have tried using Bitmap,Is there a way to use WIC(Windows imaging component) to combine multiple images.
class Program
{
static void Main(string[] args)
{
int width = 0;
int height = 0;
List<Image> images = new List<Image>();
var folderPath = "C:\\home\\imagepath";//contains all the images
var file = Directory.GetFiles(folderPath, "*.png");
String jpg3 = @"finalimage.png";
var path = "C:\\home\\data\\FinalImage";
foreach (var item in file)
{
Image image1 = Image.FromFile(item);
images.Add(image1);
width += image1.Width; // adding all the images width
height = image1.Height;
}
Bitmap finalImage = new Bitmap(width, height, PixelFormat.Format32bppArgb);
finalImage.MakeTransparent();
Graphics g = Graphics.FromImage(finalImage);
// g.Clear(SystemColors.AppWorkspace);
g.Clear(Color.White);
var nextwidth = 0;
foreach (var img in images)
{
g.DrawImage(img, new Point(nextwidth, 0));
nextwidth += img.Width;
}
g.Dispose();
foreach (var img in images)
{
img.Dispose();
}
finalImage.Save(Path.Combine(path, jpg3), ImageFormat.Png);// getting error when combining more than 12 images and saving in particular folder
finalImage.Dispose();
}
}
"Error :System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'"
Getting this error on finalImage.save(path.combine(path,jpg3),ImageFormat.Png);