Create Vignette

Pipeline Drawing Channels Vignette

Creates a vignette with a specified color.

Сode Snippet

const float borderScale = 0.05f;
const float blurRadiusScale = borderScale / 2.0f;

using (var reader = ImageReader.Create("Venice.jpg"))
using (var gc = new GraphicsContainer(reader.Width, reader.Height, reader.DpiX, reader.DpiY))
using (var gr = gc.GetGraphics())
{
    int offset = (int)(reader.Width * borderScale);

    gr.FillEllipse(new SolidBrush(RgbColor.White), offset, offset, gc.Width - (2 * offset), gc.Height - (2 * offset));

    // One pipeline for generating an alpha channel
    var alphaPipeline = new Pipeline();
    alphaPipeline.Add(new ImageGenerator(gc, PixelFormat.Format8bppGrayscale, RgbColor.Black));
    alphaPipeline.Add(new Blur(reader.Width * blurRadiusScale));

    // And another one for getting a final content
    var pipeline = new Pipeline();
    pipeline.Add(reader);
    pipeline.Add(new ScaleAlpha(alphaPipeline));
    pipeline.Add(new RemoveAlpha(RgbColor.White));
    pipeline.Add(ImageWriter.Create("VeniceVignette.jpg"));

    try
    {
        pipeline.Run();
    }
    finally
    {
        pipeline.DisposeAllElements();
        alphaPipeline.DisposeAllElements();
}

Input

Venice.jpg

Output

VeniceVignette.jpg

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog