Search code examples
c#gdi+photos

Put one image below other one


Im not good in working with pictures, what I want is to merge two pictures, but I need a i second picture to be below the first one. Like

[Image1]
[Image2]

Example: I have two images of the size 320x240px. I want an image 320x480px with the content of Image1 in the top half and Image2 in the bottom half.


Solution

  •         Image image1 = GetFirstImage();
    
            Image image2 = GetSecondImage();
    
            var bitmapImage = new Bitmap(Math.Max(image1.Width, image2.Width), (image1.Height + image2.Height));
    

    //.....

            using (Graphics g = Graphics.FromImage(bitmapImage))
            {
                g.DrawImage(image1, 0, 0);
                g.DrawImage(image2, 0, image1.Height);
            }