'''' 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.Text '' 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).PublicClassTransparencyMaskPublicFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap Dim h2 AsInteger = pixelSize.Width \ 2 '' Prepare a linear gradient transparency mask,'' from 0 (transparent) to 255 (opaque):Using mask AsNewGcBitmap(h2, h2, True)Using gmask = mask.CreateGraphics()Dim grad = NewLinearGradientBrush(Color.Black, Color.White) gmask.FillRectangle(NewRectangleF(0, 0, mask.Width, mask.Height), grad)EndUsing'' Convert to GrayscaleBitmap to be used as Renderer.TransparencyMaskBitmap:Using gsb = mask.ToGrayscaleBitmap() '' Create a bitmap to draw on, fill it with yellow background:Using bmp1 AsNewGcBitmap(h2, h2, True)Using 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:Dim d AsSingle = CSng(h2) / 25.0!Dim rc AsNewRectangleF(0, 0, h2 * 0.7F, h2 * 0.7F) Dim 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 = NothingFillCircles(g, rc, h2, d) bmp.BitBlt(bmp1, h2, 0) '' Add some explanatory texts below the images:Dim gg = bmp.CreateGraphics() rc = NewRectangleF(0, h2 + d, h2 - d * 2, h2 - d * 2)Dim tf = NewTextFormat() With { .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 bmpEndUsingEndUsingEndUsingEndUsingEndFunction PrivateSubFillCircles(ByVal g AsGcBitmapGraphics, ByVal rc AsRectangleF, ByVal h2 AsSingle, ByVal d AsSingle)Dim 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)EndSubEndClass