I have a requirement wherein I need to merge two different png/jpeg images resulting into a single image using C#.Net. There will be a particular location defined on the source image wherein I need to insert another image. Can anybody suggest some links ?
Open the Photo Gallery and locate the folder that contains photos you want to combine. Hold CTRL key to select multiple images and then click on the Photo Gallery's Create tab. Select the Photo Fuse feature and proceed to designate the area of the photo you want to replace.
Merging two imagesCreate an empty image using the Image. new() function. Paste the images using the paste() function. Save and display the resultant image using the save() and show() functions.
This method merge two images one in the top of the other you can modify the code to meet for your needs:
public static Bitmap MergeTwoImages(Image firstImage, Image secondImage) { if (firstImage == null) { throw new ArgumentNullException("firstImage"); } if (secondImage == null) { throw new ArgumentNullException("secondImage"); } int outputImageWidth = firstImage.Width > secondImage.Width ? firstImage.Width : secondImage.Width; int outputImageHeight = firstImage.Height + secondImage.Height + 1; Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(outputImage)) { graphics.DrawImage(firstImage, new Rectangle(new Point(), firstImage.Size), new Rectangle(new Point(), firstImage.Size), GraphicsUnit.Pixel); graphics.DrawImage(secondImage, new Rectangle(new Point(0, firstImage.Height + 1), secondImage.Size), new Rectangle(new Point(), secondImage.Size), GraphicsUnit.Pixel); } return outputImage; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With