//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Imaging; namespaceDsImagingWeb.Demos{// This sample demonstrates how to make a round clipping of a part of an image// and render it into a GcBitmap.publicclassRoundCLip {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {// 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:var backColor = Color.FromArgb(unchecked((int)0xff0066cc));var foreColor = Color.FromArgb(unchecked((int)0xffffcc00));constintbottom = 144, pad = 36;int minSize = Math.Min(pixelSize.Width, pixelSize.Height) / 6, maxSize = (int)(Math.Min(pixelSize.Width, pixelSize.Height) / 1.5); // Randomize some parameters of the sample:var rnd = Common.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 (var 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:constintx = 143, y = 0, w = 655, h = 655; // Create a clipping region excluding all outside of the specified circle:var rgn = newGrapeCity.Documents.Imaging.Region(newRectangularFigure(0, 0, bmpSrc.PixelWidth, bmpSrc.PixelHeight));var 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();var renderer = bmpSrc.Renderer; renderer.ClipRegion = rgn; renderer.Clear(Color.Transparent);var size = rnd.Next(minSize, maxSize);using (var bmpRound = bmpSrc.Clip(newRectangle(x, y, w, h)))using (var bmpSmall = bmpRound.Resize(size, size)) {var 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 bmp; } } } }}