'''' 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 shows how a color spectrum with fall offs from fully saturated'' colors to white and black can be easily created using linear gradient brushes'' and GcBitmap.Renderer.TransparencyMaskBitmap.PublicClassColorSpectrumPublicFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap '' Color spectrum gradient brush:Dim spec = NewLinearGradientBrush(Color.Red, Color.Red)Dim stepVal AsSingle = 1.0F / 6.0F spec.GradientStops = NewGradientStop() {NewGradientStop(Color.Yellow, stepVal),NewGradientStop(Color.Green, stepVal * 2),NewGradientStop(Color.Cyan, stepVal * 3),NewGradientStop(Color.Blue, stepVal * 4),NewGradientStop(Color.Magenta, stepVal * 5) } '' Create the spectrum in a separate temp bitmap:Dim spectrumSz = NewSize(pixelSize.Width, CInt(pixelSize.Height * 0.75F)) '' Falloff brush and mask:Using tbmp AsNewGcBitmap(spectrumSz.Width, spectrumSz.Height, True)Using tgfx = tbmp.CreateGraphics()'' Black is opaque, White transparent:Dim falloff = NewLinearGradientBrush(Color.Black, PointF.Empty, Color.Black, NewPointF(0, 1))'' Additional gray stops provide a more gradual and pleasing appearance: falloff.GradientStops = NewGradientStop() {NewGradientStop(Color.LightGray, 0.35F),NewGradientStop(Color.White, 0.5F),NewGradientStop(Color.LightGray, 0.65F) }'' Fill the mask with the gradient that will define the transparency: tgfx.FillRectangle(NewRectangleF(0, 0, tbmp.Width, tbmp.Height), falloff) '' Convert mask to grayscale for use as the transparency mask:Using mask = tbmp.ToGrayscaleBitmap() '' Reuse the original mask bitmap;'' Fill it with a gradient from white at the top to black at the bottom:Dim grad = NewLinearGradientBrush(Color.White, PointF.Empty, Color.Black, NewPointF(0, 1)) tgfx.FillRectangle(NewRectangleF(0, 0, spectrumSz.Width, spectrumSz.Height), grad) '' Add transparency mask and draw the gradient: tbmp.Renderer.TransparencyMaskBitmap = mask tgfx.FillRectangle(NewRectangleF(PointF.Empty, spectrumSz), spec) '' Copy spectrum to the target bitmap:Dim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi) bmp.BitBlt(tbmp, 0, 0) '' Add some explanatory texts below the spectrum:Dim g = bmp.CreateGraphics()Dim rc = NewRectangleF(0, spectrumSz.Height, spectrumSz.Width, bmp.PixelHeight - spectrumSz.Height)Dim tf = NewTextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMonoBold.ttf")), .FontSize = 14 } g.FillRectangle(rc, Color.LightGray) g.DrawString("The color spectrum is drawn using a horizontal linear gradient brush with 7 stops:" & vbLf &"Red - Yellow - Green - Cyan - Blue - Magenta - Red." & vbLf &"The background is filled with a vertical gradient from white to black. " &"A TransparencyMaskBitmap with a vertical gradient that changes from 0 " &"(opaque) to 1 (transparent) back to 0 (opaque) provides falloffs " &"from spectrum colors in the center up to white and down to black backgrounds.", tf, rc, TextAlignment.Center, ParagraphAlignment.Center) Return bmpEndUsingEndUsingEndUsingEndFunctionEndClass