---
title: "Overlaying Images"
canonical: https://www.graphicsmill.com/docs/gm/overlaying-images-advanced-drawing.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 blending modes and set the foreground image coordinates. This topic describes both the simple and masked overlaying of images, and provides code snippets for the watermarking and making a collage.
 
## Simple Overlaying
  
There are two ways to overlay bitmaps in Graphics Mill:
 
1. Using the [Graphics.DrawImage](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage.htm.md) method. An [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 [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");
    }
    ```
2. Using the [Bitmap.Draw](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Bitmap_Draw.htm.md) method. This method should be called 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:
 
**Note** 
This method takes values of the [Transforms.CombineMode](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_CombineMode.htm.md) enumeration, which is out of date.
 
```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);
    
        bitmap.Draw(watermark, 10, bitmap.Height - watermark.Height - 40,
            CombineMode.Alpha);
        bitmap.Save(@"Images\Output\out.jpg");
    }
    ```

The watermarked image:
 
![Watermarking an image using alpha blending mode](https://www.graphicsmill.com/docs/gm/OverlayingImages.jpg)
 
## Overlaying Using Masks
  
Another way to combine images is to use one of the masked transforms, such as the [Blender](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Blender.htm.md) transform. Masked transforms allow for 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 **Blender** transform, you can create a collage from several images on the same background, like the following one:
 
![A collage created using Blender](https://www.graphicsmill.com/docs/gm/OverlayingImages2.jpg)
 
In the collage above, two photos are inserted into 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's 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 **Blender** transform. You can set the blending mode by passing it as a constructor argument.
4. Specify the photo to combine via the [Blender.TopImage](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Blender_TopImage.htm.md) property.
5. Apply the **Blender** 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 blender = new Blender(Aurigma.GraphicsMill.Transforms.BlendMode.Normal);

    //Combine with the first image.
    blender.TopImage = photo1;
    blender.X = point1.X - photo1.Width / 2;
    blender.Y = point1.Y - photo1.Height / 2;
    collage = blender.ApplyMaskTransform(background, mask);

    //Combine with the second image.
    blender.TopImage = photo2;
    blender.X = point2.X - photo2.Width / 2;
    blender.Y = point2.Y - photo2.Height / 2;
    collage = blender.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 Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Graphics.htm.md)
- [Blender Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Blender.htm.md)
- [BlendMode Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_BlendMode.htm.md)
- [ApplyMaskTransform(Bitmap, Bitmap) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_MaskTransform_ApplyMaskTransform_2_5c3e6481.htm.md)

### Manual
 
- [Blending Modes](https://www.graphicsmill.com/docs/gm/blending-modes.htm.md)
- [Combine Modes](https://www.graphicsmill.com/docs/gm/combine-modes.htm.md)
