|
|
[C#]
using (Bitmap bm = new Bitmap(600, 800)) {
using (Graphics graphics = Graphics.FromImage(bm)) {
Pen pen = new Pen(Color.Black, 8);
Font font = new Font("Arial", 10);
StringFormat format = new StringFormat() { Alignment = 0.5, LineAlignment = 1.0 };
RectangleF rect = bm.Bounds;
rect.Inflate(-100, -50);
graphics.DrawLine(Pens.Red, rect.TopLeft, rect.BottomLeft);
graphics.DrawLine(Pens.Red, rect.TopRight, rect.BottomRight);
rect.Height = pen.Width * 3;
foreach (LineCap cap in (LineCap[])Enum.GetValues(typeof(LineCap))) {
if (cap == LineCap.Custom || cap == LineCap.AnchorMask)
continue;
pen.StartCap = pen.EndCap = cap;
graphics.DrawLine(pen, rect.TopLeft, rect.TopRight);
graphics.DrawString(pen.StartCap.ToString(), font, Brushes.Black, rect, format);
rect.Offset(0, pen.Width * 5);
}
}
bm.Save(Server.MapPath("IG8_Pen_LineCap.png"));
}
The code here iterates through the different types of line caps
to show what they look like. The final output is shown below.

IG8_Pen_LineCap.png
|