---
title: "Artistic Frame"
canonical: https://www.graphicsmill.com/samples/Drawing/DrawingImages/ArtisticFrame_cs
product: "Graphics Mill"
source: "Drawing/DrawingImages/ArtisticFrame.cs"
---

# Artistic Frame

Draws artistic frame.

## Instruction

Write a C# program that creates an artistic photo frame by loading a main image "Copenhagen_Rgb.jpg", matt pattern "Matt.png", and frame pattern "Frame.png", then composes them using AdvancedGraphics with tiled matt background, rotated and clipped frame borders on all four sides using Path clipping, centered image placement with double light gray border, and saves the result as "DrawArtisticFrame.png".

## Usings

```csharp
using System;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
var repeatBitmap = (Bitmap bitmap, int minWidth, int minHeight) =>
{
    int tileXCount = ((minWidth - 1) / bitmap.Width) + 1;
    int tileYCount = ((minHeight - 1) / bitmap.Height) + 1;

    var repeated = new Bitmap(tileXCount * bitmap.Width, tileYCount * bitmap.Height, PixelFormat.Format24bppRgb);

    using (var graphics = repeated.GetGraphics())
    {
        for (var i = 0; i < tileXCount; i++)
        {
            for (var j = 0; j < tileYCount; j++)
            {
                graphics.DrawImage(bitmap, bitmap.Width * i, bitmap.Height * j);
            }
        }
    }

    return repeated;
};

int padding = 200;

using (var source = new Bitmap("Copenhagen_Rgb.jpg"))
{
    int width = source.Width + (padding * 2);
    int height = source.Height + (padding * 2);

    var mattPath = "Matt.png";
    var framePath = "Frame.png";

    using (var result = new Bitmap(width, height, PixelFormat.Format24bppRgb))
    using (var graphics = result.GetGraphics())
    {
        // Draw matt
        using (var matt = new Bitmap(mattPath))
        {
            matt.DpiX = graphics.DpiX;
            matt.DpiY = graphics.DpiY;
            using (var mattRepeated = repeatBitmap(matt, result.Width, result.Height))
            {
                // Draw centered
                graphics.DrawImage(mattRepeated, 0, 0);
            }

            // Draw frame
            using (var frame = new Bitmap(framePath))
            {
                frame.DpiX = graphics.DpiX;
                frame.DpiY = graphics.DpiY;
                using (var frameRepeated = repeatBitmap(frame, frame.Width, Math.Max(result.Height, result.Width)))
                {
                    // Right border
                    graphics.DrawImage(frameRepeated, 0, 0);

                    // Left border
                    frameRepeated.Transforms.Rotate(180f);
                    graphics.DrawImage(frameRepeated, result.Width - frameRepeated.Width, 0);

                    // Top border
                    frameRepeated.Transforms.Rotate(270f);

                    var clippingPathTop = new Path();
                    clippingPathTop.MoveTo(0f, 0f);
                    clippingPathTop.LineTo((float)result.Width / 2f, (float)result.Width / 2f);
                    clippingPathTop.LineTo(result.Width, 0);
                    clippingPathTop.Close();

                    graphics.ClippingPaths.Add(clippingPathTop);

                    graphics.DrawImage(frameRepeated, 0, 0);

                    graphics.ClippingPaths.Clear();

                    // Bottom border
                    frameRepeated.Transforms.Rotate(180f);

                    var clippingPathBottom = new Path();
                    clippingPathBottom.MoveTo(0f, result.Height);
                    clippingPathBottom.LineTo((float)result.Width / 2f, (float)result.Height - ((float)result.Width / 2f));
                    clippingPathBottom.LineTo(result.Width, result.Height);
                    clippingPathBottom.Close();

                    graphics.ClippingPaths.Add(clippingPathBottom);

                    graphics.DrawImage(frameRepeated, 0, result.Height - frameRepeated.Height);

                    graphics.ClippingPaths.Clear();

                    // Draw image in the center
                    var rect1 = new System.Drawing.RectangleF(
                        (result.Width - source.Width) / 2,
                        (result.Height - source.Height) / 2,
                        source.Width,
                        source.Height);

                    graphics.DrawImage(source, rect1);

                    var pen = new Pen(RgbColor.LightGray, 4f);

                    graphics.DrawRectangle(pen, rect1);

                    float offset = 8f;

                    var rect2 = new System.Drawing.RectangleF(
                        rect1.X - offset,
                        rect1.Y - offset,
                        rect1.Width + (offset * 2),
                        rect1.Height + (offset * 2));

                    graphics.DrawRectangle(pen, rect2);
                }
            }
        }

        result.Save("DrawArtisticFrame.png");
    }
}
```

## Explanation

Below is a C# code sample that creates a complex artistic frame composition:

The code demonstrates advanced GraphicsMill drawing techniques including: lambda-based bitmap tiling for repeating patterns, DPI synchronization between layers, frame border construction using 90-degree rotations with triangular Path clipping for corners, centered image placement with offset double border using Pen drawing, and comprehensive using statement resource management. The composition creates professional photo frame effects with seamless matt background, properly mitered frame corners via clipping paths, and decorative borders around the centered subject image.

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text

## Input

- [Copenhagen\_Rgb.jpg](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/Copenhagen_Rgb_jpg>) (preview)
- [Matt.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/Matt_png>) (preview)
- [Frame.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/Frame_png>) (preview)

## Output

- [DrawArtisticFrame.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/DrawArtisticFrame_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.Transforms](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Transforms.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.ClippingPaths](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_ClippingPaths.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawImage(Bitmap,RectangleF)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage_2_2fdc9815.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawImage(Bitmap,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage_3_b9413d4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawRectangle(Pen,RectangleF)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawRectangle_2_169e24a7.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Close](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Close.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.LineTo(Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_LineTo_2_427c5821.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.MoveTo(Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_MoveTo_2_427c5821.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.htm.md>)
- [Aurigma.GraphicsMill.TransformsProvider.Rotate(Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_TransformsProvider_Rotate_1_7a94462e.htm.md>)
