'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing '' This sample demonstrates how to use GcGraphics.PushClip/PopClip'' methods to specify clipping.PublicClassPushClipFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap Dim backColor = Color.FromArgb(&HFF0066CC)Dim foreColor = Color.FromArgb(&HFFFFCC00)Dim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)Dim cw = 400, ch = 300, pad = 10, bord = 4Dim clipRc = NewRectangleF(pixelSize.Width - cw - pad, pad, cw, ch)Using g = bmp.CreateGraphics(backColor)'' We create a path consisting of two nested rectangles,'' outer for the whole bitmap, inner for a text box.'' We then use that path to create a clip region And'' draw an image covering the whole bitmap but excluding'' the text boxUsing gpath = g.CreatePath() gpath.BeginFigure(PointF.Empty) gpath.AddLine(NewPointF(pixelSize.Width, 0)) gpath.AddLine(NewPointF(pixelSize.Width, pixelSize.Height)) gpath.AddLine(NewPointF(0, pixelSize.Height)) gpath.EndFigure(FigureEnd.Closed) gpath.BeginFigure(NewPointF(clipRc.Left, clipRc.Top)) gpath.AddLine(NewPointF(clipRc.Right, clipRc.Top)) gpath.AddLine(NewPointF(clipRc.Right, clipRc.Bottom)) gpath.AddLine(NewPointF(clipRc.Left, clipRc.Bottom)) gpath.EndFigure(FigureEnd.Closed)Using cliprgn = g.CreateClipRegion(gpath)Using img = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "clivia.jpg")) g.PushClip(cliprgn) g.DrawImage( img,NewRectangleF(0, 0, pixelSize.Width, pixelSize.Height),Nothing,ImageAlign.StretchImage) g.PopClip(cliprgn)EndUsingEndUsingEndUsing'' We now draw some text inside the text box,'' clipping to it (this overload of PushClip'' returns an IDisposable that removes the clipping'' when disposed)Using (g.PushClip(clipRc)) g.DrawString( Util.LoremIpsum(),NewTextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")), .FontSize = 16, .ForeColor = foreColor }, clipRc )EndUsing'' Draw a border around the whole image,'' demonstrating that the clip has been removed: g.DrawRectangle(NewRectangleF(bord / 2, bord / 2, pixelSize.Width - bord, pixelSize.Height - bord),NewGCDRAW.Pen(foreColor, bord))EndUsing'' DoneReturn bmpEndFunctionEndClass