You could use DrawingVisual and RenderTargetBitmap to create the overlapping image, then just change the Image.Source property. Here is an example:
public static class ImageExtensions
{
public static void Merge(this Image image1, Image image2, Rect r)
{
// Get sources from each image
BitmapImage source1 = (BitmapImage)image1.Source;
BitmapImage source2 = (BitmapImage)image2.Source;
// Overlap images and save to image 1
image1.Source = OverlapImages(source1, source2, r);
}
private static BitmapSource OverlapImages(BitmapImage image1, BitmapImage image2, Rect r)
{
// Create a DrawingVisual to combine the images
DrawingVisual visual = new DrawingVisual();
using (DrawingContext ctx = visual.RenderOpen())
{
// Draw the first image
ctx.DrawImage(image1, new Rect(0, 0, image1.Width, image1.Height));
// Draw the second image on top
ctx.DrawImage(image2, r);
}
// Render the visual into a RenderTargetBitmap
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
(int)Math.Max(image1.PixelWidth, image2.PixelWidth),
(int)Math.Max(image1.PixelHeight, image2.PixelHeight),
96, 96, PixelFormats.Pbgra32);
renderBitmap.Render(visual);
return renderBitmap;
}
}
You can then use the extension in your code. Example:
// Load data into image 1
BitmapImage bmp1 = new BitmapImage();
bmp1.BeginInit();
bmp1.UriSource = new Uri("your path goes here");
bmp1.EndInit();
image1.Source = bmp1;
// Load data into image 2
BitmapImage bmp2 = new BitmapImage();
bmp2.BeginInit();
bmp2.UriSource = new Uri("your path goes here");
bmp2.EndInit();
image2.Source = bmp2;
// Merge image 2 into image 1
image1.Merge(image2, new Rect(15, 15, 100, 100));
The image1 will now display both the image1 and image2.