//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Drawing;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Imaging;usingGCTEXT = GrapeCity.Documents.Text; namespaceDsImagingWeb.Demos{// This sample demonstrates the use of TransparencyMaskBitmap// when drawing on a bitmap. The transparency mask used is// created on the fly by filling an intermediary bitmap// with a linear gradient brush from 0 (black, transparent)// to 255 (white, opaque).publicclassTransparencyMask {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {var h2 = pixelSize.Width / 2; // Prepare a linear gradient transparency mask,// from 0 (transparent) to 255 (opaque):usingvar mask = newGcBitmap(h2, h2, true);usingvar gmask = mask.CreateGraphics();var grad = newLinearGradientBrush(Color.Black, Color.White); gmask.FillRectangle(newRectangleF(0, 0, mask.Width, mask.Height), grad);// Convert to GrayscaleBitmap to be used as Renderer.TransparencyMaskBitmap:usingvar gsb = mask.ToGrayscaleBitmap(); // Create a bitmap to draw on, fill it with yellow background:usingvar bmp1 = newGcBitmap(h2, h2, true);usingvar g = bmp1.CreateGraphics(Color.Yellow); // Apply the transparency mask: g.Renderer.TransparencyMaskBitmap = gsb; // Fill 3 circles, note how the fill gradually changes// from transparent to opaque (left to right) along with the gradient:var d = h2 / 25f;var rc = newRectangleF(0, 0, h2 * 0.7f, h2 * 0.7f); var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi); bmp.Clear(Color.White);FillCircles(g, rc, h2, d); bmp.BitBlt(bmp1, 0, 0); g.Renderer.TransparencyMaskBitmap = null;FillCircles(g, rc, h2, d); bmp.BitBlt(bmp1, h2, 0); // Add some explanatory texts below the images:var gg = bmp.CreateGraphics(); rc = newRectangleF(0, h2 + d, h2 - d * 2, h2 - d * 2);var tf = newTextFormat() {Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf")),FontSize = 16 }; gg.DrawString("The circles in the image above were rendered with TransparencyMaskBitmap " +"on the target graphics set to a linear gradient from transparent to opaque.", tf, rc, TextAlignment.Center, ParagraphAlignment.Near); rc.Offset(h2, 0); gg.DrawString("The circles in the image above were rendered with no TransparencyMaskBitmap " +"on the target graphics.", tf, rc, TextAlignment.Center, ParagraphAlignment.Near); return bmp; } voidFillCircles(GcBitmapGraphics g, RectangleF rc, float h2, float d) {var r = rc; r.Offset((h2 - rc.Width) / 2, 0); r.Inflate(-d, -d); g.FillEllipse(r, Color.Red); r = rc; r.Offset(h2 - rc.Width, h2 - rc.Height); r.Inflate(-d, -d); g.FillEllipse(r, Color.Green); r = rc; r.Offset(0, h2 - rc.Height); r.Inflate(-d, -d); g.FillEllipse(r, Color.Blue); } }}