Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to merge multiple image dynamically in c# in vertically and give the space between two images and all image merge in own original size(Big size or how to increase size of image)

Help me out
Thanks

What I have tried:

C#
public void MergeImages(List<Image> imageList)
{
    
    string jpg3 = "Save path";
    int heights = 0;
    int nIndex = 0;

    List<int> widths = new List<int>();
    foreach (Image image in imageList)
    {
        widths.Add(image.Width);
        heights += image.Height;


    }
    widths.Sort();
    int width = widths[widths.Count - 1];

    Bitmap img3 = new Bitmap(width, heights);
    Graphics g = Graphics.FromImage(img3);
    g.Clear(Color.White);
    foreach (Image image in imageList)
    {
        Image img = image;
        if (nIndex == 0)
        {
            g.DrawImage(img, new Point(0, 0));
            nIndex++;
            width = img.Height;
        }
        else
        {

            g.DrawImage(img, new Point(0, width));
            width += img.Height;
        }
        img3.Save(jpg3, System.Drawing.Imaging.ImageFormat.Jpeg);
        img.Dispose();
    }
    g.Dispose();
    try
    {
        img3.Save(jpg3, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    catch (Exception ex)
    {

    }
    img3.Dispose();
}
Posted
Updated 15-Mar-21 23:00pm
v2
Comments
Richard Deeming 16-Mar-21 5:01am    
Aside from the lack of using blocks, and the fact that you're swallowing and ignoring all exceptions, what is the problem with the code you've tried?
Member 13698531 16-Mar-21 9:59am    
Image merge is properly but image size is too much small and during merge image ,images not have margin from top one image to other image ,all image is clinging to each other.
i want space between all image like a white space and how can i increase size of image during merge.

Thanks for response
Richard Deeming
[no name] 16-Mar-21 13:04pm    
More math.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900