# Blend Modes

DsPdf supports blend modes in its API like Normal, multiply, color dodge, lighten, overlay etc.

## Content

Blend modes are used in computer graphics to determine how colors are blended, or mixed, with each other when drawing on a surface that already contains color information. In other words, a blend mode determines the resulting color of a colored pixel when another color is applied to it. The default is BlendMode.Normal, which simply replaces the original color with the new one.
The [GcPdfGraphics ](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfGraphics.html)class supports blend modes by providing PDF-specific overrides of its base [GcGraphics](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.GcGraphics.html) class's abstract members:

* [BlendMode](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.GcGraphics.BlendMode.html) Property: Gets or sets the current blend mode. The blend mode that is set using this property remains in effect for all the subsequent drawing on the current GcPdfGraphics, until changed to another value. Note that the current blend mode affects all drawing on the graphics (including text), not just images.
* [IsBlendModeSupported](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.GcGraphics.IsBlendModeSupported.html) Method: All blend modes are not supported in PDF (in particular, Hue, Saturation, Color and Luminosity are not supported). This method allows to programmatically check whether a particular blend mode is supported or not. An attempt to set an unsupported blend mode will throw an exception.

The below image shows different blend modes applied to two images in a PDF document:
![](https://cdn.mescius.io/document-site-files/images/884d2bfb-301b-49bc-8d90-656c5b910507/images/blend_modes_pdf.png)
To apply blend modes:

1. Load images on which blend modes will be applied using [FromFile](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.Image.FromFile.html) method of [Image ](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.Image.html)class.
2. Create a text layout which will be used to add captions for different blend modes by instantiating [CreateTextLayout](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.GcGraphics.CreateTextLayout.html) method and using different properties of [TextLayout](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Text.TextLayout.html) class.
3. Apply different blend modes on the loaded images by using the [BlendMode](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Drawing.GcGraphics.BlendMode.html) property and rendering all the images in a grid.

    ```csharp
    var doc = new GcPdfDocument();
    var page = doc.NewPage();
    var g = page.Graphics;
    
    var iorchid = Image.FromFile(Path.Combine("Resources", "ImagesBis", "orchid.jpg"));
    var ispectr = Image.FromFile(Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png"));
    
    const int margin = 36;
    const int NCOLS = 4;
    var w = (int)((page.Size.Width - margin * 2) / NCOLS);
    var h = (int)((iorchid.Height * w) / iorchid.Width);
    
    // Text layout for captions:
    var tl = g.CreateTextLayout();
    tl.DefaultFormat.Font = Font.FromFile(Path.Combine("Resources", "Fonts", "cour.ttf"));
    tl.DefaultFormat.FontSize = 12;
    tl.ParagraphAlignment = ParagraphAlignment.Center;
    tl.TextAlignment = TextAlignment.Center;
    tl.MaxWidth = w;
    tl.MaxHeight = h;
    tl.MarginTop = h - g.MeasureString("QWERTY", tl.DefaultFormat).Height * 1.4f;
    
    int row = 0, col;
    // Render all blending modes in a grid:
    var modes = Enum.GetValues(typeof(BlendMode));
    for (int i = 0; i < 2; ++i)
    {
        row = col = 0;
        Image iback, ifore;
        if (i == 0)
        {
            iback = ispectr;
            ifore = iorchid;
        }
        else // i == 1
        {
            iback = iorchid;
            ifore = ispectr;
            page = doc.Pages.Add();
            g = page.Graphics;
        }
        foreach (var mode in modes)
        {
            var blendMode = (BlendMode)mode;
            if (!g.IsBlendModeSupported(blendMode))
                continue;
    
            int x = margin + w * col;
            int y = margin + h * row;
            var r = new RectangleF(x, y, w, h);
    
            g.BlendMode = BlendMode.Normal;
            g.DrawImage(iback, r, null, ImageAlign.StretchImage);
            g.BlendMode = blendMode;
            g.DrawImage(ifore, r, null, ImageAlign.StretchImage);
            g.BlendMode = BlendMode.Normal;
    
            // Caption:
            tl.Clear();
            tl.Append(blendMode.ToString());
            tl.PerformLayout(true);
            var rc = tl.ContentRectangle;
            rc.Offset(x, y);
            rc.Inflate(4, 2);
            g.FillRectangle(rc, Color.White);
            g.DrawTextLayout(tl, new PointF(x, y));
            nextRowCol();
        }
    }
    doc.Save(stream);
    //
    void nextRowCol()
    {
        if (++col == NCOLS)
        {
            col = 0;
            ++row;
        }
    }
    ```

**Limitation**
The Hue, Saturation, Color, and Luminosity blend modes are not supported in DsPdf as they are not supported in the PDF specification.