Vignette is an artistic effect designed to draw attention to the center of the image. Classically vignetting reduces brightness or saturation at the periphery of the image, but vignettes can have different shapes, widths, and colors. This topic describes how to create vignettes using Graphics Mill.
The following image illustrates a classical vignette:
Creating such a vignette includes the following steps:
The following code adds a classical vignette to an image:
using (var bitmap = new Bitmap(@"Images\in.jpg")) { //Create mask bitmap using (var mask = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format8bppGrayscale, RgbColor.Black)) { using (var graphics = mask.GetAdvancedGraphics()) { graphics.FillEllipse(new SolidBrush(RgbColor.White), 50, 50, bitmap.Width - 100, bitmap.Height - 100); //Apply blur transform mask.Transforms.Blur(40); //Add the mask to the alpha channel bitmap.Channels.SetAlpha(mask); //Flatten alpha channel bitmap.Channels.RemoveAlpha(RgbColor.Black); bitmap.Save(@"Images\Output\out.jpg"); } } }
The described approach opens wide horizons for creativity. For example, it allows you to create vignettes of different shapes (hearts, diamonds, stars, clouds or any other). Using Aurigma.GraphicsMill.AdvancedDrawing.Graphics you can draw curves of almost any shape.
The other technique, which is somewhat slower but offers even more possibilities, is based on combining two images. This technique includes the following steps:
The following image illustrates an advanced vignette:
The following code adds an advanced vignette to an image:
using (var bitmap = new Bitmap(@"Images\in.jpg")) { //Create an ovelaying bitmap and an empty mask. It will be opaque as it is filled with white using (var overlay = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format32bppArgb, RgbColor.Pink)) using (var mask = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format8bppGrayscale, RgbColor.White)) { System.Drawing.PointF[] points = { new System.Drawing.PointF(20, 10), new System.Drawing.PointF(overlay.Width-20, 10), new System.Drawing.PointF(overlay.Width-10, 20), new System.Drawing.PointF(overlay.Width-10, overlay.Height-20), new System.Drawing.PointF(overlay.Width-20, overlay.Height-10), new System.Drawing.PointF(20, overlay.Height-10), new System.Drawing.PointF(10, overlay.Height-20), new System.Drawing.PointF(10, 20), new System.Drawing.PointF(20, 10) }; using (var graphics = mask.GetAdvancedGraphics()) { //Draw a polygon graphics.FillPolygon(new SolidBrush(RgbColor.Black), points); //Add blur effect mask.Transforms.Blur(7); //Replace the alpha channel of the overlay with the mask overlay.Channels[Channel.Alpha] = mask; //Put the ovelaying bitmap over the source image bitmap.Draw(overlay, 0, 0, overlay.Width, overlay.Height, CombineMode.Screen, 1.0f, ResizeInterpolationMode.High); bitmap.Save(@"Images\Output\out.jpg"); } } }