To draw on an image within Pipeline use the Drawer class. This class allows you to draw on Graphics. To learn how to draw with Graphics in detail, read the Drawing Text and Graphics section. The Drawer class provides the Draw event handler where you should implement all the drawing functionality.
The fact that pipelines process large images by stripes means that Draw event is fired for each stripe. So it is recommended to create all resource-intensive objects in the BeginDraw event handler and release them in EndDraw.
We will discuss below how to draw geometrics primitives and vector text using Pipeline. In addition, you can observe the Transforming Images with Pipelines article to learn to combine images with pipelines.
The snippet below illustrates how to draw a white border around an image. Read the Graphics: Drawing Images and Geometric Shapes article to learn how to utilize drawing operations.
using (var reader = ImageReader.Create(@"Images\in.jpg")) using (var drawer = new Drawer()) using (var writer = ImageWriter.Create(@"Images\Output\out.jpg")) { drawer. Draw += delegate(object sender, DrawEventArgs e) { var pen = new Pen(System.Drawing.Color.White, 20); e.Graphics.DrawRectangle(pen, new System.Drawing.Rectangle(10, 10, e.Width - 20, e.Height - 20)); }; Pipeline.Run(reader + drawer + writer); }
Graphics allows drawing various types of vector text described in the Drawing Text article. The code below extracts a date and time of image creation from EXIF and draws it on an image as PlainText. To learn about EXIF metadata in detail read in the EXIF and IPTC Metadata topic.
using (var reader = ImageReader.Create(@"Images\in.jpg")) { if (reader.Exif != null) { string dateTime = reader.Exif[ExifDictionary.DateTime].ToString(); using (var drawer = new Drawer()) using (var writer = ImageWriter.Create(@"Images\Output\out.jpg")) { drawer.Draw += delegate(object sender, DrawEventArgs e) { var text = new PlainText(dateTime, e.Graphics.CreateFont("Courier New", e.Height / 20), new SolidBrush(RgbColor.Red), new System.Drawing.PointF(450, 150), TextAlignment.Right); e.Graphics.DrawText(text); }; Pipeline.Run(reader + drawer + writer); } } }