forked from Uzi-Granot/PdfFileWriter
-
Notifications
You must be signed in to change notification settings - Fork 1
3.6 Draw Happy Face
OgreTransporter edited this page Mar 2, 2020
·
1 revision
The DrawHappyFace
method is an example of drawing oval and constructing path from a line and Bezier curve.
// Draw Happy Face
private void DrawHappyFace()
{
// save graphics state
Contents.SaveGraphicsState();
// translate coordinate origin to the center of the happy face
Contents.Translate(4.25, 7.5);
// change nonstroking (fill) color to yellow
Contents.SetColorNonStroking(Color.Yellow);
// draw happy face yellow oval
Contents.DrawOval(-1.5, -1.0, 3.0, 2.0, PaintOp.Fill);
// set line width to 0.2" this is the black circle around the eye
Contents.SetLineWidth(0.2);
// eye color is white with black outline circle
Contents.SetColorNonStroking(Color.White);
Contents.SetColorStroking(Color.Black);
// draw eyes
Contents.DrawOval(-0.75, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke);
Contents.DrawOval(0.25, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke);
// mouth color is black
Contents.SetColorNonStroking(Color.Black);
// draw mouth by creating a path made of one line and one Bezier curve
Contents.MoveTo(-0.6, -0.4);
Contents.LineTo(0.6, -0.4);
Contents.DrawBezier(0.0, -0.8, 0, -0.8, -0.6, -0.4);
// fill the path with black color
Contents.SetPaintOp(PaintOp.Fill);
// restore graphics sate
Contents.RestoreGraphicsState();
return;
}
This page is a copy from https://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library by Uzi Granot. The article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL). All rights to the texts and source code remain with Uzi Granot.