'''' 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.TextImports GCDRAW = GrapeCity.Documents.Drawing '' This sample demonstrates how to use different grayscale effects.'' See also MatrixEffects1 and MatrixEffects2.PublicClassThresholdingEffectsFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap opaque = FalseDim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)Using origBmp = NewGcBitmap()'' Load a sample photo:Dim imagePath = Path.Combine("Resources", "Stock", "bw-hiking.jpg")Using stm = NewFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess) origBmp.Load(stm)EndUsing origBmp.SetAlphaTo255() origBmp.Opaque = False '' Resize the original photo so we can place 4 samples of it'' on the resulting bitmap:Dim w = pixelSize.Width / 2Dim h = pixelSize.Height / 2Using sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic)'' Copy the resized original into 4 quadrants of the resulting bitmap: bmp.BitBlt(sizedBmp, 0, 0) bmp.BitBlt(sizedBmp, w, 0) bmp.BitBlt(sizedBmp, 0, h) bmp.BitBlt(sizedBmp, w, h)EndUsing Dim lineh = 2 '' Keep the pixels in top left quadrant intact,'' apply effects to the other 3 quadrants'' (these effects make sense for grayscale images only, so we do it before adding captions): bmp.ApplyEffect(OtsuThresholdingEffect.Get(), NewRectangle(w + lineh, 0, w - lineh, h - lineh)) bmp.ApplyEffect(BradleyThresholdingEffect.Get(), NewRectangle(0, h + lineh, w - lineh, h - lineh)) bmp.ApplyEffect(BradleyThresholdingEffect.Get(16, 6), NewRectangle(w + lineh, h + lineh, w - lineh, h - lineh)) '' Add borders between the quadrants, And captions for eachUsing g = bmp.CreateGraphics(Nothing)Dim foreColor = Color.YellowDim backColor = Color.BlueDim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf")) g.DrawLine(w, 0, w, h * 2, NewGCDRAW.Pen(foreColor, lineh * 2)) g.DrawLine(0, h, w * 2, h, NewGCDRAW.Pen(foreColor, lineh * 2))Dim tf = NewTextFormat() With {.Font = fnt, .FontSize = 18, .ForeColor = foreColor, .BackColor = backColor, .FontBold = True} g.DrawString(" Original image ", tf, NewPointF(0, 0)) g.DrawString(" OtsuThresholdingEffect ", tf, NewPointF(w + lineh, 0)) g.DrawString(" BradleyThresholdingEffect ", tf, NewPointF(0, h + lineh)) g.DrawString(" BradleyThresholdingEffect(16,6) ", tf, NewPointF(w + lineh, h + lineh))EndUsingEndUsing'' DoneReturn bmpEndFunctionEndClass