'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.NumericsImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.Imaging '' This sample demonstrates how to make a round clipping of a part of an image'' and render it into a GcBitmap.PublicClassRoundCLipFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap '' Note: we can use Color.Transparent instead of a solid background,'' but the resulting image format must support transparency for this'' to work as expected:Dim backColor = Color.FromArgb(&HFF0066CC)Dim foreColor = Color.FromArgb(&HFFFFCC00)Constbottom = 144, pad = 36Dim minSize = Math.Min(pixelSize.Width, pixelSize.Height) / 6, maxSize = (Math.Min(pixelSize.Width, pixelSize.Height) / 1.5) '' Randomize some parameters of the sample:Dim rnd = Util.NewRandom() '' It is a good idea to dispose bitmaps which are no longer needed,'' so we are 'using' all bitmaps except the one returned:Using bmpSrc = NewGcBitmap(Path.Combine("Resources", "Stock", "woman-brick-wall.jpg"))'' Make sure source and target opacity match: bmpSrc.Opaque = opaque '' Coordinates and size of the clipping in the source image:Constx = 143, y = 0, w = 655, h = 655 '' Create a clipping region excluding all outside of the specified circle:Dim rgn = NewGrapeCity.Documents.Imaging.Region(NewRectangularFigure(0, 0, bmpSrc.PixelWidth, bmpSrc.PixelHeight))Dim ellipse = NewEllipticFigure(x, y, w, h) rgn.CombineWithRegion(NewGrapeCity.Documents.Imaging.Region(ellipse), RegionCombineMode.Exclude, False) '' To clip using a Region, we need to use the BitmapRenderer:'' NOTE (New in v2sp2) the renderer Is Not created by Default,'' we must call EnsureRendererCreated() prior to using it: bmpSrc.EnsureRendererCreated()Dim renderer = bmpSrc.Renderer renderer.ClipRegion = rgn renderer.Clear(Color.Transparent)Dim size = rnd.Next(minSize, maxSize)Using bmpRound = bmpSrc.Clip(NewRectangle(x, y, w, h))Using bmpSmall = bmpRound.Resize(size, size)Dim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi) bmp.Clear(Color.Transparent) bmp.BitBlt(bmpSmall, rnd.Next(pad, pixelSize.Width - pad - bmpSmall.PixelWidth), rnd.Next(pad, pixelSize.Height - pad - bottom - bmpSmall.PixelHeight))Return bmpEndUsingEndUsingEndUsingEndFunctionEndClass