---
title: "Overlaying Images"
canonical: https://www.graphicsmill.com/docs/gm/overlaying-images.htm
product: "Graphics Mill"
---

# Overlaying Images
 
Graphics Mill provides rich image blending features. It allows the overlaying of images, including masked overlaying. Also you can select one of many available combine modes and set the foreground image coordinates. The topic describes both simple and masked overlaying of images, and provides watermarking and making of a collage code snippets.
 
## Simple Overlaying
  
There are two ways to overlay bitmaps in Graphics Mill:
 
1. Using the [Bitmap.Draw](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Bitmap_Draw.htm.md) method. The method should be called for the background bitmap, and the foreground bitmap is passed as an argument of the method.
2. Using the [Graphics.DrawImage](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage.htm.md) method. A [Drawing.Graphics](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Graphics.htm.md) instance is created for the background bitmap, and the foreground bitmap is passed as an argument of the method.

The following code adds a semitransparent watermark to an image using the [Bitmap.Draw(Bitmap, Int32, Int32, CombineMode)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_Draw_4_335ea9fd.htm.md) method:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var watermark = new Bitmap(@"Images\watermark.png"))
{
    //Make the watermark semitransparent.
    watermark.Channels.ScaleAlpha(0.8F);

    //Watermark image
    bitmap.Draw(watermark, 10, bitmap.Height - watermark.Height - 40, CombineMode.Alpha);

    //Save the resulting image
    bitmap.Save(@"Images\Output\out.jpg");
}
```
 
The following code adds a semitransparent watermark to an image using the [Graphics.DrawImage(Bitmap, Single, Single, Single)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage_4_af468bea.htm.md) method:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var watermark = new Bitmap(@"Images\watermark.png"))
using (var graphics = bitmap.GetGraphics())
{
    graphics.DrawImage(watermark, 10, bitmap.Height - watermark.Height - 40, 0.8f);
    bitmap.Save(@"Images\Output\out.jpg");
}
```
 
The watermarked image:
 
![Watermarking an image using alpha blending combine mode](https://www.graphicsmill.com/docs/gm/OverlayingImages.jpg)
 
The code above utilizes the [Alpha](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_CombineMode.htm.md) combine mode. This mode preserves the opacity of the foreground image. For more information see the [Combine Modes](https://www.graphicsmill.com/docs/gm/combine-modes.htm.md) topic.
 
## Overlaying Using Masks
  
Another way to combine images is to use one of masked transforms, the [Combiner](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Combiner.htm.md) transform. Masked transform allows applying effects to a region defined by a mask. All transforms which can be applied with a mask have a common base class, [MaskTransform](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_MaskTransform.htm.md). Using the **Combiner** transform you can create a collage from several images on the same background, like the following one:
 
![A collage created using Combiner](https://www.graphicsmill.com/docs/gm/OverlayingImages2.jpg)
 
In the collage above two photos are inserted to the placeholders over a background. The following diagram illustrates the idea:
 
![Masked transform diagram](https://www.graphicsmill.com/docs/gm/OverlayingImages3.jpg)
 
To create a collage like this you should perform the following steps:
 
1. Define the mask bitmap. The mask should be a grayscale image ([Format8bppGrayscale](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_PixelFormat_Format8bppGrayscale.htm.md)) of the same size as the background image. White areas of the mask are placeholders. If the placeholder area edges are blurred, it will result in a gradient effect at the edges.
2. Define the placeholder coordinates. They will be used to position the photos.
3. Create the **Combiner** transform. You can set the combine mode by passing it as a constructor argument. For more information see the [Combine Modes](https://www.graphicsmill.com/docs/gm/combine-modes.htm.md) topic.
4. Specify the photo to combine via the [Combiner.TopImage](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Combiner_TopImage.htm.md) property.
5. Apply the **Combiner** transform using the [MaskTransform.ApplyMaskTransform(Bitmap, Bitmap)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_MaskTransform_ApplyMaskTransform_2_5c3e6481.htm.md) method and save the result.
6. Repeat Steps 4 and 5 for the second photo.
7. Save the resulting image to a file.

The following code creates a collage from the two photos, given mask and background images:
 
```csharp
using (var photo1 = new Bitmap(@"Images\monkey.jpg"))
using (var photo2 = new Bitmap(@"Images\dog.jpg"))
using (var background = new Bitmap(@"Images\CollageBackground.jpg"))
using (var mask = new Bitmap(@"Images\CollageMask.jpg"))
{
    //Resulting collage.
    var collage = new Bitmap();

    //Coordinates of placeholders.
    var point1 = new System.Drawing.Point(130, 165);
    var point2 = new System.Drawing.Point(460, 200);

    //Create the transform.
    var combiner = new Combiner(CombineMode.Copy);

    //Combine with the first image.
    combiner.TopImage = photo1;
    combiner.X = point1.X - photo1.Width / 2;
    combiner.Y = point1.Y - photo1.Height / 2;
    collage = combiner.ApplyMaskTransform(background, mask);

    //Combine with the second image.
    combiner.TopImage = photo2;
    combiner.X = point2.X - photo2.Width / 2;
    combiner.Y = point2.Y - photo2.Height / 2;
    collage = combiner.ApplyMaskTransform(collage, mask);

    collage.Save(@"Images\Output\collage.jpg");

    collage.Dispose();
}
```
 
## See Also
  
### Reference
 
- [Bitmap.Draw Overload](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Bitmap_Draw.htm.md)
- [Bitmap Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Bitmap.htm.md)
- [Graphics.DrawImage Overload](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage.htm.md)
- [Graphics Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Graphics.htm.md)
- [Combiner Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Combiner.htm.md)
- [MaskTransform.ApplyMaskTransform(Bitmap, Bitmap) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_MaskTransform_ApplyMaskTransform_2_5c3e6481.htm.md)

### Manual
 
- [Combine Modes](https://www.graphicsmill.com/docs/gm/combine-modes.htm.md)
