//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Imaging;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Drawing;usingGCTEXT = GrapeCity.Documents.Text; namespaceDsImagingWeb.Demos{// This sample demonstrates how to draw round rectangles// using dedicated DrawRoundRect/FillRoundRect methods.// It also shows how the same result may be achieved with// graphics paths.publicclassRoundRectangle {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);var Inch = dpi;using (var g = bmp.CreateGraphics(Color.RoyalBlue)) {var rc = Common.Util.AddNote("GcGraphics has dedicated methods to easily draw and fill rectangles with rounded corners. " +"This sample also shows how the same result may be achieved using graphics paths. " +"While they are not really needed for drawing round rectangles, graphics paths allow " +"to draw and fill arbitrary figures with complex geometries.", g); // Rounded rectangle's radii:float rx = 36, ry = 24; // Using dedicated methods to draw and fill round rectangles:var rEasy = newRectangleF(rc.Left, rc.Bottom + Inch / 2, Inch * 2, Inch); g.FillRoundRect(rEasy, rx, ry, Color.PaleGreen); g.DrawRoundRect(rEasy, rx, ry, Color.Blue, 4);// Add a label:var tf = newTextFormat() {Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")),FontSize = Inch / 6 }; g.DrawString("The easy way.", tf, rEasy, TextAlignment.Center, ParagraphAlignment.Center, false); // Using graphics path to achieve the same result:var rHard = rEasy; rHard.Offset(0, rEasy.Height + Inch / 2);var path = MakeRoundRect(g, rHard, rx, ry); g.FillPath(path, Color.PaleVioletRed); g.DrawPath(path, Color.Purple, 4);// Add a label: g.DrawString("The hard way.", tf, rHard, TextAlignment.Center, ParagraphAlignment.Center, false); // Done: }// Done:return bmp; } // This method shows how to create a graphics path that may be used// to fill or draw arbitrary shapes on a GcGraphics.privateIPathMakeRoundRect(GcGraphics g, RectangleF rc, float rx, float ry) {var path = g.CreatePath();var sz = newSizeF(rx, ry);// start from horizontal top left path.BeginFigure(newPointF(rc.Left + rx, rc.Top)); path.AddLine(newPointF(rc.Right - rx, rc.Top)); path.AddArc(newArcSegment() { Point = newPointF(rc.Right, rc.Top + ry), SweepDirection = SweepDirection.Clockwise, Size = sz }); path.AddLine(newPointF(rc.Right, rc.Bottom - ry)); path.AddArc(newArcSegment() { Point = newPointF(rc.Right - rx, rc.Bottom), SweepDirection = SweepDirection.Clockwise, Size = sz }); path.AddLine(newPointF(rc.Left + rx, rc.Bottom)); path.AddArc(newArcSegment() { Point = newPointF(rc.Left, rc.Bottom - ry), SweepDirection = SweepDirection.Clockwise, Size = sz }); path.AddLine(newPointF(rc.Left, rc.Top + ry)); path.AddArc(newArcSegment() { Point = newPointF(rc.Left + rx, rc.Top), SweepDirection = SweepDirection.Clockwise, Size = sz }); path.EndFigure(FigureEnd.Closed);return path; } }}