GaussianBlur.vb
'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports SystemImports System.IOImports System.DrawingImports GrapeCity.Documents.DrawingImports GrapeCity.Documents.TextImports GrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing
'' This sample demonstrates how to use the GaussianBlurEffect.Public Class GaussianBlur Public Function GenerateImage( ByVal pixelSize As Size, ByVal dpi As Single, ByVal opaque As Boolean, Optional ByVal sampleParams As String() = Nothing) As GcBitmap
opaque = False Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi) Using origBmp As New GcBitmap() '' Load a sample photo: Dim imagePath = Path.Combine("Resources", "ImagesBis", "butterfly.jpg") Using stm = New FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess) origBmp.Load(stm) End Using
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 \ 2 Dim h = pixelSize.Height \ 2 Using 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) End Using
'' Keep the pixels in top left quadrant intact, '' apply effects to the other 3 quadrants: Dim lineh = 2 bmp.ApplyEffect(GaussianBlurEffect.Get(), New Rectangle(w + lineh, 0, w - lineh, h - lineh)) bmp.ApplyEffect(GaussianBlurEffect.Get(Color.Blue, 4, GaussianBlurBorderMode.Bounce), New Rectangle(0, h + lineh, w - lineh, h - lineh)) bmp.ApplyEffect(GaussianBlurEffect.Get(Color.Blue, 16, GaussianBlurBorderMode.Mirror), New Rectangle(w + lineh, h + lineh, w - lineh, h - lineh))
'' Add borders between the quadrants, and captions for each: Using g = bmp.CreateGraphics(Nothing) Dim foreColor = Color.Yellow Dim backColor = Color.Blue Dim font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf")) g.DrawLine(w, 0, w, h * 2, New GCDRAW.Pen(Color.Gray, lineh * 2)) g.DrawLine(0, h, w * 2, h, New GCDRAW.Pen(Color.Gray, lineh * 2)) Dim tf = New TextFormat() With { .Font = font, .FontSize = 18, .ForeColor = foreColor, .BackColor = backColor, .FontBold = True } Dim th = g.MeasureString("QWERTY", tf).Height g.DrawString(" Original image ", tf, New PointF(0, h - th + lineh)) g.DrawString(" Default Gaussian blur ", tf, New PointF(w + lineh, h - th + lineh)) g.DrawString(" Radius 5px, bounce border ", tf, New PointF(0, h * 2 + lineh - th + lineh)) g.DrawString(" Radius 16px, mirror border ", tf, New PointF(w + lineh, h * 2 + lineh - th + lineh)) End Using End Using Return bmp End FunctionEnd Class