---
title: "Invert Background"
canonical: https://www.graphicsmill.com/samples/PSDFormat/RenderTemplates/InvertBackground_cs
product: "Graphics Mill"
source: "PSDFormat/RenderTemplates/InvertBackground.cs"
---

# Invert Background

Inverts background layer of PSD image and saves to PDF file.

## Instruction

Write a C# program that processes "BusinessCard.psd" using PSD processor with custom FrameCallback to detect raster frames, applies Invert transform to invert pixel values of background layer, converts processed frame to GraphicsContainer using ResizeMode.ImageFill for layout preservation, and renders the modified PSD layers to PDF output "InvertBackground.pdf" via psdProcessor.Render method.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs.Psd;
using Aurigma.GraphicsMill.Templates;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
var psdProcessor = new PsdProcessor();

var psName = psdProcessor.FontResolver.FontRegistry.Add("ARIALUNI.TTF")[0].PostscriptName;
psdProcessor.FontResolver.FontRegistry.FallbackFonts.Add(psName);

psdProcessor.FrameCallback = (processor, frame) =>
{
    if (frame.Type != FrameType.Raster)
    {
        return processor.ProcessFrame(frame);
    }

    using (var invert = new Invert())
    {
        return frame.ToGraphicsContainer(frame + invert, ResizeMode.ImageFill);
    }
};

psdProcessor.Render("BusinessCard.psd", "InvertBackground.pdf");
```

## Explanation

Below is a C# code sample that inverts background layer of PSD and exports to PDF:

The code demonstrates PSD processing pipeline using custom FrameCallback to selectively apply Invert transform only to raster frames (skipping vector/text layers), converting inverted raster content to GraphicsContainer with ImageFill resizing mode to maintain design layout, while preserving non-background layers unchanged. The PSD processor handles layer composition, transparency, and effects, rendering the modified document to PDF format suitable for print production workflows where background inversion is needed for design variations or negative image effects.

## Tags

- [Personalization](<https://www.graphicsmill.com/samples/tags/personalization_md>): Replacing placeholders with dynamic content
- [PSD Processor](<https://www.graphicsmill.com/samples/tags/psd-processor_md>): Automating PSD-based personalization

## Input

- [BusinessCard.psd](<https://www.graphicsmill.com/samples/PSDFormat/compiled/Debug/BusinessCard_psd>) (download)

## Output

- [InvertBackground.pdf](<https://www.graphicsmill.com/samples/PSDFormat/compiled/Debug/InvertBackground_pdf>) (download)
- [InvertBackground.png](<https://www.graphicsmill.com/samples/PSDFormat/compiled/Debug/InvertBackground_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.Psd.FrameType](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_Psd_FrameType.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Psd.PsdFrame.Type](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_Psd_PsdFrame_Type.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CustomFontRegistry.Add(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_CustomFontRegistry_Add_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontAddResult.PostscriptName](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontAddResult_PostscriptName.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontRegistry.FallbackFonts](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontRegistry_FallbackFonts.htm.md>)
- [Aurigma.GraphicsMill.Templates.FontResolver.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Templates_FontResolver_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Templates.PsdFrameExtensions.ToGraphicsContainer(PsdFrame,Pipeline,ResizeMode)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Templates_PsdFrameExtensions_ToGraphicsContainer_3_2f902f24.htm.md>)
- [Aurigma.GraphicsMill.Templates.PsdProcessor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Templates_PsdProcessor.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Invert](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Invert.htm.md>)
- [Aurigma.GraphicsMill.Transforms.ResizeMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeMode.htm.md>)
